设置ember多态belongsTo关系的值

时间:2015-09-04 14:37:02

标签: inheritance ember.js polymorphism ember-data

我正在尝试设置一个ember polymorphic belongsTo的值,并且我一直得到一个TypeError:无法从ember读取未定义的属性'modelName'。

以下是我的模特:

// handle.js
import DS from "ember-data";
export default DS.Model.extend({
    username: DS.attr('string'),
    incoming: DS.hasMany('request', { async: true, inverse: 'actor'     }),
    outgoing: DS.hasMany('request', { async: true, inverse: 'requestor' })
});

// community.js
import DS from "ember-data";
import Handle from "./handle";
export default Handle.extend({
    name: DS.attr('string')
});

// request.js
import DS from "ember-data";
export default DS.Model.extend({
    requestor: DS.belongsTo('handle', { async: true, polymorphic: true, inverse: 'outgoing' }),
    actor: DS.belongsTo('handle', { async: true, polymorphic: true, inverse: 'incoming' }),
});

现在,我在社区变量中保存了一个现有的社区模型,我正在尝试创建一个新的Request模型:

this.store.createRecord('request', {
    actor: community
}).save();

问题是,这会产生以下堆栈跟踪错误:

TypeError: Cannot read property 'modelName' of undefined
at ember$data$lib$system$store$$Service.extend.modelFor (http://localhost:4200/assets/vendor.js:70084:22)
at ember$data$lib$system$store$$Service.extend.recordForId (http://localhost:4200/assets/vendor.js:69478:30)
at ember$data$lib$system$store$$deserializeRecordId (http://localhost:4200/assets/vendor.js:70600:27)
at http://localhost:4200/assets/vendor.js:70581:11
at http://localhost:4200/assets/vendor.js:72491:20
at Map.forEach.cb (http://localhost:4200/assets/vendor.js:24194:11)
at OrderedSet.forEach (http://localhost:4200/assets/vendor.js:23987:11)
at Map.forEach (http://localhost:4200/assets/vendor.js:24198:18)
at Function.ember$data$lib$system$model$$default.reopenClass.eachRelationship (http://localhost:4200/assets/vendor.js:72490:83)
at ember$data$lib$system$store$$normalizeRelationships (http://localhost:4200/assets/vendor.js:70577:12)

我无法弄清楚我做错了什么。我正在使用ember-cli和ember v1.12。

PS我简化了模型,省略了(我认为的)更不重要的细节。

0 个答案:

没有答案