我需要将其他参数传递给 Ember-Model 的 belongsTo。我让它与它自己的属性类型一起工作。但我也需要有关系。这有可能吗?
UserType = {
serialize: function(objectId) {
return {
__type: 'Pointer',
className: '_User',
objectId: objectId
};
},
deserialize: function(object) {
return object.objectId;
}
};
App.Movie = Ember.Model.extend({
objectId: Ember.attr(),
createdAt: Ember.attr(),
updatedAt: Ember.attr(),
owner: Ember.attr(UserType),
// owner: Ember.belongsTo('App.User', {
// key: 'objectId'
// }),
});
App.User = Ember.Model.extend({
objectId: Ember.attr(),
username: Ember.attr(),
email: Ember.attr(),
createdAt: Ember.attr(),
updatedAt: Ember.attr(),
});
App.User.primaryKey = 'objectId';
这是电影的 JSON:
{
"ratings": [
{
"objectId": "AQWYN32UUo",
"value": 4
}
],
"title": "Inception",
"watched": true,
"year": "2010",
"owner": {
"__type": "Pointer",
"className": "_User",
"objectId": "AQWYN32UUo"
},
"createdAt": "2013-11-28T15:38:40.730Z",
"updatedAt": "2013-11-28T15:55:37.114Z",
"objectId": "0x5tdCcWiy"
},
谢谢