EmberJS insert/set an Object at Index in hasMany


#1

Say I have a Person who has many Dogs:

App.Person = DS.Model.extend
   name: DS.attr 'string'
   dogs: DS.hasMany 'elements',
       embedded: 'always'

App.Dog = DS.Model.extend
   owner: DS.belongsTo 'person'

Is it possible to do something like that:

person = store.createRecord 'person', hash

person.get('dogs').set objectAt(N), someDog

I’d like to replace the dog in person at index N with some other dog.


#2

You could use replace: person.get('dogs').replace(N, 1, [someDog]). I can’t comment on what effects that has on Ember Data, try it out?


#3

Hey man, Thanks. I was looking under Ember.Array instead.