I am unable to save parent records in a hasMany/belongsTo relationship. When I save the record, it forgets who its children are.
The objects are defined like so:
// We're using ember-data...
MF.Store = DS.Store.extend({
adapter: DS.FixtureAdapter
});
// Two objects, a parent...
MF.Parent = DS.Model.extend({
name: DS.attr(),
childs: DS.hasMany('child')
});
MF.Parent.FIXTURES = []; // ...with fixtures
// ...and a child
MF.Child = DS.Model.extend({
name: DS.attr(),
parent: DS.belongsTo('parent')
});
MF.Child.FIXTURES = [];
I have tried the following order of operations with the same end results in each.
- Set Child's Parent. Save the Child. Save the Parent
- Set Child's Parent. Save the Parent.
- Add Child to Parent. Save Parent.
- Add Child to Parent. Save Child. Save Parent.
There's a live demo you can see here on GitHub.
setand this automatically updates my UI without callingsave. - steakchaser