我有一个使用'RSVP.hash'创建模型的路线,如下例所示:
model: function(params){
return Ember.RSVP.hash({
customer: this.store.findRecord('customer', params.customer_id),
address: this.store.createRecord('address')
});
我想保存模型的“地址”部分? model.save()给出了结果:'未捕获TypeError:模型不是函数'我该怎么做才能只保存模型的地址部分?
这是保存模型的操作:
createAddress: function(model){
console.log(model.address.constructor);
model.address.save();
}
模型(地址):
import DS from 'ember-data';
export default DS.Model.extend({
id_address: DS.attr('number'),
id_customer_fb: DS.attr(),
id_customer: DS.attr('number'),
id_supplier: DS.attr('number'),
id_state: DS.attr('number'),
id_country: DS.attr('number'),
postcode: DS.attr('string'),
active: DS.attr('boolean'),
address1: DS.attr('string'),
address2: DS.attr('string'),
city: DS.attr('string'),
alias: DS.attr('string'),
company: DS.attr('string'),
vat_number: DS.attr('string'),
firstname: DS.attr('string'),
lastname: DS.attr('string'),
other: DS.attr('string'),
phone: DS.attr('string'),
phone_mobile: DS.attr('string'),
deleted: DS.attr('boolean'),
// date_add: DS.attr('date'),
// date_upd: DS.attr('date'),
customer: DS.belongsTo('customer')
});
模特客户:
import DS from 'ember-data';
export default DS.Model.extend({
id_count: DS.attr('number'),
id_customer: DS.attr('number'),
id_default_group: DS.attr('number'),
id_lang: DS.attr('number'),
id_gender: DS.attr('number'),
active: DS.attr('boolean'),
email: DS.attr(),
firstname: DS.attr(),
lastname: DS.attr(),
company: DS.attr(),
birthday: DS.attr('date'),
date_add: DS.attr('date'),
date_upd: DS.attr('date'),
max_payment_days: DS.attr('number'),
newsletter: DS.attr('boolean'),
note: DS.attr(),
website: DS.attr(),
addresses: DS.hasMany('address')
});
答案 0 :(得分:0)
您正在使用的model
只不过是哈希。所有承诺解决后,Ember.RSVP.hash({})
只返回一个哈希值。
因此,在您的情况下,如果您只想保存地址,可以model.address.save()