Model containing array of objects of a certain type, playing nicely with isDirty?


#1

I’d like to have a model, for example Team, that has an attribute that is an array of objects of a certain type, for example Player. Each Player object would follow a defined schema, but these Player objects are owned wholly by the given Team record. The hasMany option seems to assume that the Player objects are first-class citizens that have site-wide unique IDs, can be accessed elsewhere in the store, etc. I just want a Team model to include a list of Players, with isDirty work working accordingly, so if a Player is changed or added or deleted, the Team is dirty. Is this possible?


#2

you could add an arrayObserver to the ‘players’-array. http://emberjs.com/api/classes/Ember.Array.html#method_addArrayObserver

Whenever a player is added or removed you can dirty the parent:

teamHolyMaccaroni.send('becomeDirty')