Ember.js id来自已创建记录的余烬数据模型如何?
我正在创建一个包含以下元素的余烬数据模型。是否可以将发票行中的Ember.js id来自已创建记录的余烬数据模型如何?,ember.js,ember-data,Ember.js,Ember Data,我正在创建一个包含以下元素的余烬数据模型。是否可以将发票行中的equalTo设置为新创建发票的id model: function() { return Ember.RSVP.hash({ parameter: this.store.findRecord('parameter',1), invoice: this.store.createRecord('customerinvoice',{ order_reference : '', ord
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')
});
}
在不查看存储和序列化程序的代码的情况下,我可以建议首先创建记录,然后从中提取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')
});
}
另一件事,不必创建所有初始化为空字符串的customerinvoice
属性,您可以为ember模型定义默认值,如果省略属性,将添加这些默认值:
export default Model.extend({
order_reference: attr('string', { defaultValue: '' })
// rest of the properties and their default values...
});
然后您可以创建一个记录而不传递任何内容
this.store.createRecord('customerinvoice');
在不查看存储和序列化程序的代码的情况下,我可以建议首先创建记录,然后从中提取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')
});
}
另一件事,不必创建所有初始化为空字符串的customerinvoice
属性,您可以为ember模型定义默认值,如果省略属性,将添加这些默认值:
export default Model.extend({
order_reference: attr('string', { defaultValue: '' })
// rest of the properties and their default values...
});
然后您可以创建一个记录而不传递任何内容
this.store.createRecord('customerinvoice');
创建
CustomerVoice
记录时,如何分配id
?您是否更改了primaryKey
或执行了其他操作?我将余烬数据与firebase bakend一起使用-当您调用store.createRecord
时,该id由firebaseNot(默认情况下)自动创建。这将在本地创建一个记录,并且只有在对其调用save()
时才会将其发布到后端。您是否使用特定的序列化程序为您创建id?然后我认为ember data会创建id,因为我在emberinspector中看到了id(id不能在emberfire的模型中定义)。根据您提供的信息,我在回答中给了您一个建议。旁注:当使用store.createRecord
时,id
默认情况下是通过适用于您的型号的适配器的generateIdForRecord
功能创建的。这意味着您很可能正在使用为您创建id的特定适配器。在创建customerinvoice
记录时,如何分配id
?您是否更改了primaryKey
或执行了其他操作?我将余烬数据与firebase bakend一起使用-当您调用store.createRecord
时,该id由firebaseNot(默认情况下)自动创建。这将在本地创建一个记录,并且只有在对其调用save()
时才会将其发布到后端。您是否使用特定的序列化程序为您创建id?然后我认为ember data会创建id,因为我在emberinspector中看到了id(id不能在emberfire的模型中定义)。根据您提供的信息,我在回答中给了您一个建议。旁注:当使用store.createRecord
时,id
默认情况下是通过适用于您的型号的适配器的generateIdForRecord
功能创建的。这意味着您很可能正在使用为您创建id的特定适配器。