本文介绍了StrongLoop:EmbedsMany vs hasMany和belongTo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序具有此事件模型.如果我创建另一个模型:日期...,那么一个事件可以有多个日期,我应该使用事件EmbedsMany日期吗?还是最好使用事件hasMany Dates和Dates AresToEvent来使用事件?有什么区别?

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.

我可能正在使用MySQL数据库,不知道是否有事要做.

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

推荐答案

查询具有 EmbedsMany 关系将在结果中包含相关详细模型的实例.这是因为如果使用SQL数据库,则子模型将以文档的形式保留在主表的字段中.

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 存储相关模型的ID,由您自己决定您是否要在查询中包括相关模型的实例.在这种情况下,主数据和明细数据将存储在单独的表中.

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.

这篇关于StrongLoop:EmbedsMany vs hasMany和belongTo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 16:59