I'm using Angular's $resource
to fetch/update my Project objects, a simplified version looks like this:
{
_id: "12345",
name: "whatever",
revisions: [
{ _id: "67890",
comments: [
{ _id: "13579", body: "here's a comment" }
]
}
}
So each Project contains an array of Revision objects, which contain an array of Comment objects, and I have an ID for each.
My application is useless without the whole project object, so it seems like the most efficient thing to do is to request the Project only once when the page loads. Lets say I wanted to update or add a Revision (which is an array of child objects), I think the ideal situation would be that I could locate that Revision object and then call $save
on it. The problem is that the child objects of the Project do not inherit the functions that $resource
gives to the root Project object.
I realize that I could just update the Revision object in my scope and then call $save
on the Project, but my app requires a very specific behavior when Revisions are created, that is different from when Projects are updated, that is different from when Comments are created, etc.
I know that I could create a new type of $resource
called Revision and give it it's own unique URL, but in order to update that object, I will need to have requested it in the first place (inefficient, right?).
Does anyone have any suggestions on how I should go about solving this problem? Am I better off using $http
than $resource
?
If you only fetch the data once and you don't need to update it much, it might be better using $http
and jsonp
. $resource
is using $http
internally, so not much difference in the long run.