Reputation: 599
what is the right way to use ngResource for a complex data model? There are countless one-table examples out there, but little to nothing covering 1:n and m:n relationships.
Assuming a simple 'parent' 1->n 'child' relationship, and the entry point is always through parent: is it necessary to create a $resource for parent and child, and call save() on the child for each time a new related child is created, passing the parent_id? Or did my way of thinking not arrive in the Angular world yet, and I should try to save() the parent only having ngResource taking care of the rest?
Upvotes: 3
Views: 1732
Reputation: 408
ngResource is great but doesn't 'really' handle relationships and might be lacking a few things you need. What you have proposed - "create a $resource for parent and child, and call save() on the child for each time a new related child is created, passing the parent_id" - would be correct; however I would strongly recommend looking at either Restangular or Restmod
Both are great and there are some other ones out there too. My personal recommendation for be Restmod as I find it handles relationships better.
Upvotes: 5
Reputation: 13158
$resource
is just another implementation of a NoSQL data store paradigm through HTTP requests. There are many references out there on how to manage relationships between NoSQL entities (for example, many to many relationship with nosql (mongodb and mongoose))
Upvotes: 0