angularjs $resource 和 one-to-many 关系

angularjs $resource and one-to-many relationship

将 ngResource 用于复杂数据模型的正确方法是什么? 那里有无数 one-table 示例,但几乎没有涵盖 1:n 和 m:n 关系。

假设一个简单的'parent' 1->n 'child'关系,并且入口点总是通过parent:是否有必要为[=26=创建一个$resource ] 和 child,并在每次创建新的相关 child 时调用 child 上的 save(),传递 parent_id?或者我的思维方式还没有到达 Angular 世界,我应该尝试 save() parent 只让 ngResource 处理其余的?

ngResource 很棒,但不 'really' 处理关系,可能缺少您需要的一些东西。您提出的建议 - "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" - 是正确的;但是我强烈建议您查看 Restangular or Restmod

两者都很棒,还有其他一些。我个人推荐使用 Restmod,因为我发现它可以更好地处理人际关系。

$resource 只是 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))

的另一种实现