Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extjs 5 hasMany vs field.reference

I'm struggling to understand the different types of data bindings in ExtJS and I couldn't figure this out:

What is the difference between "hasMany" and "field.reference" when defining associations on two models?

When should I use "hasMany" and when is "reference" better?

For example, if I want to define multiple email addresses to one user, what is the best practice so I can use the email model elsewhere too?

I'm aware that I have 3 questions, but these seem to belong together.

Thanks!

like image 515
Phil Avatar asked Sep 02 '14 08:09

Phil


1 Answers

One of the best breakdowns on this I've seen is here:

https://moduscreate.com/blog/associations-in-ext-js-5/

It goes into a lot of detail, and specifically addresses your third question regarding email addresses - because the association is now defined on the child model rather than parent model, you have to have a different email model if you want to attach it to a different parent, i.e. a CustomerEmail class to attach to Customer and an AdminEmail class to attach to Admin.

There's a bit of detail for the reason for the change here:

http://www.sencha.com/blog/deep-dive-into-ext-js-5-data

Declaring associations is another area in Ext JS 5 where we have reduced boilerplate code requirements. In previous releases, the hasMany, hasOne and belongsTo configs required that you manually maintain symmetric declarations on both “sides” of an association. This is no longer the case. You can declare an association in either of the associated classes (though typically on the “many” side).

like image 164
Colin Ramsay Avatar answered Sep 20 '22 19:09

Colin Ramsay