Setting a belongsTo Relationship on a Dirty Object in Ember.js

a 夏天 提交于 2019-12-13 04:53:29

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!