Search code examples
node.jsloopbackjsstrongloop

What's the difference between hasMany and referencesMany in Strongloop loopback


I read that embedsMany (in case of non relational db) puts the embedded models in the parent model document. While hasMany creates a new collection of child model and a relation is created between parent collection and child collection. What about referencesMany?

There is also this example project, where customer referencesMany Account and hasMany Order. I am not understanding the difference.


Solution

  • embedsMany: puts all child data (naturally and relation) in itself model. each childs hasn't any id and can't be reusable in another rows). it needs just one collection for child and parent model.

    referencesMany: puts just id of child relation (reference id) in itself model and puts data in child model (no need to store parent model id in child model and child model id is reusable for another models). it needs an actual two collection for parent and child model.

    hasMany: puts child data and parent id in child model. it needs too an actual two collection;