Ember-Data. Add Child record for many2many & one2many
ember-data, ember.js
Solution
`hasMany` relationships can be manipulated through `addObject`, `addObjects` or `removeObject`.
contact.get('addresses').pushObject(address);
contact.get('addresses').removeObject(address);
You could also set contact on the address
address.set('contact', contact);
address.set('contact', null);
Also, you note that you should use the singular form for a belongsTo association (`contact` not `contacts`):
App.Address = DS.Model.extend({
street: attr('string'),
country: attr('string'),
contact: belongsTo('App.Contact')
});
Problem
JSFiddle - http://jsfiddle.net/9gA4y/1/ I have following model: ``` contact => (many2many) => tags contact => (one2many) => address ``` Ember Data Model: ``` App.Contact = DS.Model.extend({ name: attr('string'), tags: hasMany('App.Tag'), addresses: hasMany('App.Address') }); App.Address = DS.Model.extend({ street: attr('string'), country: attr('string'), contacts: belongsTo('App.Contact') }) App.Tag = DS.Model.extend({ name: attr('string'), contacts: hasMany('App.Contact') }); ``` I figured out adding New contact record - How do I associate existing, Address to Newly created contact. (one 2 Many) - How do I associate existing, Tags to Newly created contact. (Many 2 Many) - How do I delete associations in a existing contact.