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

1

8

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.

Kessinger answered 19/2, 2016 at 10:51 Comment(0)
T
9

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;

Theodolite answered 27/3, 2016 at 11:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.