1

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 Answers1

3

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.

A.Z.
  • 1,638
  • 2
  • 18
  • 27
  • Great!.. thanks. Putting more though into it, I may be creating a Attending Model also to serve as a hasManyThrough relation between User and Date. So I think a hasMany in this case would be better. – Gian Franco Olivieri Jun 17 '15 at 21:46
  • 1
    Personally I always use hasMany with SQL databases. It is more natural way then embedding related detail tables. With noSQL database like MongoDB it often makes sense to embed related model. Possible problem is a size of a document because MongoDB has size limit of 16 megabytes per document. Again it really depends on your design and requirements. – A.Z. Jun 18 '15 at 07:35