3

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?

szeta
  • 589
  • 1
  • 5
  • 21

2 Answers2

5

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.

Mark Collins
  • 378
  • 1
  • 2
  • 8
  • OK I thought so, wonder if it's even better to take the $http road for sake of flexibility. I'm not convinced to hook up to an external dependency for a very centric requirement. – szeta Mar 13 '15 at 09:06
0

$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))

Community
  • 1
  • 1
Brent Washburne
  • 12,904
  • 4
  • 60
  • 82
  • I wasn't aware that this is already considered NoSQL terrain, but see it more like a kind of object relational mapping. My backend is SQLAlchemy / Flask, and the relational data model is key to the application. Thanks for the direction, I will look into your suggestion more closely. – szeta Mar 13 '15 at 09:09