我正在使用以下元素创建Ember Data模型。是否可以将invoiceRows中的equalTo
设置为新创建的发票的id
?
model: function() {
return Ember.RSVP.hash({
parameter: this.store.findRecord('parameter',1),
invoice: this.store.createRecord('customerinvoice',{
order_reference : '',
ordernr_bol: '',
payment_method: '',
invoice_type: '',
company_name: '',
customer_city: '',
customer_country: '',
customer_email: '',
customer_first_name: '',
customer_name: '',
customer_phone: '',
customer_phone_mobile: '',
customer_postal_code: '',
customer_street_nr: '',
customer_vat_number: '',
}),
customers: this.store.findAll('customer'),
invoiceRows: this.store.query('customerinvoicerow', {
orderBy: 'id_cust_invoice_fb',
equalTo: **THIS MUST BE ID OF CREATED INVOICE ???????**
}),
products: this.store.findAll('product')
});
}
答案 0 :(得分:0)
没有查看商店和序列化程序的代码,我可以建议首先创建记录,然后从中提取id并将其用于剩余的承诺:
model: function() {
// create the invoice first
const invoice = this.store.createRecord('customerinvoice', { /* ... */ });
// then create the promises
return Ember.RSVP.hash({
parameter: this.store.findRecord('parameter', 1),
invoice, // pass the invoice here
customers: this.store.findAll('customer'),
invoiceRows: this.store.query('customerinvoicerow', {
orderBy: 'id_cust_invoice_fb',
equalTo: invoice.get('id') // Extract the ID here
}),
products: this.store.findAll('product')
});
}
另一件事,您可以为ember模型定义默认值,而不是创建初始化为空字符串的所有customerinvoice
属性,如果省略属性,则会添加这些默认值:
export default Model.extend({
order_reference: attr('string', { defaultValue: '' })
// rest of the properties and their default values...
});
然后你可以创建一个记录而不传递任何东西。
this.store.createRecord('customerinvoice');