I really don't get it here...
I have the following code:
App.Instance = DS.Model.extend({
hash: DS.attr('string'),
users: DS.hasMany('user', { embedded: 'always' })
});
App.User = DS.Model.extend({
name: DS.attr('string'),
color: DS.attr('string'),
lat: DS.attr('number'),
lng: DS.attr('number'),
instance: DS.belongsTo('instance')
});
App.InstanceSerializer = DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
attrs: {
users: { embedded: 'always' }
}
});
And instance like so:
var instance = {
hash: "68309966ec7fbaac",
id: "54b4518fcbe12d5160771ebe",
users: [{
color: "#9E463C",
id: "78b662bc56169a96",
lat: 36.5299487,
lng: -6.2921774,
name: "User 1"
},{
color: "#9E463C",
id: "78b662bc56169a96",
lat: 36.5299487,
lng: -6.2921774,
name: "User 2"
}]
}
But when I want to store.push('instance', instance);
, I receive:
Uncaught Error: Assertion Failed: Ember Data expected a number or string to represent the record(s) in the
users
relationship instead it found an object. If this is a polymorphic relationship please specify atype
key. If this is an embedded relationship please include theDS.EmbeddedRecordsMixin
and specify theusers
property in your serializer's attrs
Where is the mistake?
Read from all those sources, which always use a different strategy:
- http://emberjs.com/api/data/classes/DS.EmbeddedRecordsMixin.html
- How to make embedded hasMany relationships work with ember data
- Ember-data Serialize/Deserialize embedded records on 3rd level
Thanks a lot