问题
I'm using Ember.js 1.0 and Ember-Data 1.0.0beta2. I have a couple of related models:
Whistlr.Upload = DS.Model.extend
organizations: DS.hasMany('organization')
Whistlr.Organization = DS.Model.extend
upload: DS.belongsTo('upload')
The user creates the Upload within the Organization form via Jquery File Upload. In the success callback, I set the relationship like so:
upload = @get('parentView').get('controller').store.createRecord('upload', response.upload)
@get('parentView').get('controller').set('upload', upload)
Unfortunately, it's getting set to null. Is this because I'm trying to set the relationship while both the Organization and Upload instances are dirty?
回答1:
You're setting the upload on the controller instead of on a model. You probably want to do :
@get('parentView').get('controller.model').set('upload', upload)
来源:https://stackoverflow.com/questions/19149404/setting-a-belongsto-relationship-on-a-dirty-object-in-ember-js