StrongLoop: EmbedsMany vs hasMany and belongTo

百般思念 提交于 2019-12-11 09:16:02

问题


My App has this Events Models. If I create another Model: Dates... so an Event can have multiple Dates, should I use Events EmbedsMany Dates? or is better to use Events hasMany Dates and Dates belongsTo Event? What's the difference?

New Dates to the event might be added later after the Event been created.

I might be using a MySQL database, don't know if that has something to do.


回答1:


Query on model which has EmbedsMany relation will include instance(s) of related detail model in the result. This is because child model will be persisted in a field of the master table, in a form of a document, if you are using SQL database.

HasMany stores id of related model and it is up to you are you going to include instance of related model or not in your query. In this case master and detail data will be stored in a separated tables.

What is better to use really depends on you and your needs.



来源:https://stackoverflow.com/questions/30886200/strongloop-embedsmany-vs-hasmany-and-belongto

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!