I’m fairly new to ember and ember-data and have been struggling with what is the correct approach towards handling ids on belongsTo associations.
A simple setup of my problem would be
var Parent = DS.Model.extend({});
var Child = DS.Model.extend({
parent: DS.belongsTo('parent', {async: true}),
parentId: DS.attr() // also tried adding this
});
I would like to access the parentId instead of loading the entire model in some situations but in others I would like to access the parent object. The problem is get(‘parentId’) is not always equal to get(‘parent.id’). I’ve thought of implementing synchronization but this seems like a functionality that may be built in. Am I missing something here?
example access scenario
childInstance = this.store.createRecord('child', {parent: parentInstance});
childInstance.get('parentId') === childInstance.get('parent.id'); //=> false
OR
childInstance = this.store.find('child', childId);
childInstance.get('parent').then(function(){
childInstance.get('parentId') === childInstance.get('parent.id'); //=> false
});
I had trouble setting this up with fixtures so no JSBin for this one