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.
A hasMany relation denotes a one-to-many connection of a model to another model through referential integrity. The referential integrity is enforced by a foreign key constraint on the target model which usually references a primary key on the source model.
The LoopBack framework is a set of Node. js modules that you can use independently or together to quickly build REST APIs. A LoopBack application interacts with data sources through the LoopBack model API, available locally within Node. js, remotely over REST, and via native client APIs for iOS, Android, and HTML5.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With