Pre ember-data 1.13.8 I was able to get
related records with the following syntax (this is inside of a component to comply with embers move from views):
var user = this.get('user') // The user model is passed through to the component
var classifications = user.get("Classifications"); // This would be the related records
However in ember 1.13.8 classifications
is now undefined
whereas before it was an array of related records. I have followed the transition guide but can't seem to find a reference to this change.
My user
model looks like this:
export default DS.Model.extend({
User: DS.attr('string'),
Email: DS.attr('string'),
PCTID: DS.attr('number'),
Classifications: DS.hasMany('classification'),
});
and my classification
model looks like this:
export default DS.Model.extend({
Classification: DS.attr('string'),
PostedBy: DS.attr('string'),
DatePosted: DS.attr('isodate'),
Bulletin: DS.attr('string'),
ExpireDate: DS.attr('isodate'),
Title: DS.attr('string'),
User: DS.belongsTo('user'),
UserClassification: DS.attr(),
});
Both the user
and it's classifiations
are being returned to the store and serialized into the following format:
{
"data": {
"type": "user",
"id": 1361,
"attributes": {
"User": "foo",
"Email": null,
"PCTID": 1
}
},
"included": [
{
"type": "classification",
"id": 1,
"attributes": {
"Classification": "Room",
"PostedBy": "P Hauser",
"DatePosted": "2014-09-17T00:00:00.000Z",
"Bulletin": "All data is fictitious",
"ExpireDate": null,
"Title": "Bar for foo",
"User": 1361,
"UserClassification": {
"UserId": 1361,
"ClassificationId": 1
}
}
}
]
}
How should I be getting the related records in ember-data 1.13.8?
user.get("Classifications")
or is it still in flight? – GJKClassifications: DS.hasMany('classification', { async: true })
, you should also use lower case variables (unrelated just convention), what you want to do is always set relationships toasync: true
– Patsy Issa{ async: true }
is now the default and has thus been deprecated. – Phil Hauserrelationships
out – Phil Hauser