2016-09-08 6 views
1

次の要素を持つEmber Dataモデルを作成しています。 invoiceRowsのequalToを新しく作成した請求書のidに設定することはできますか?作成したレコードのハウツーからのIDを持つemberデータモデル?

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

あなたは 'customerinvoice'レコードを作成するときに' id'をどのように割り当てるのですか? 'primaryKey'を変更したのか、それとも何かしましたか? – nem035

+0

私はfirebase bakendでember-dataを使用しています - idはfirebaseによって自動的に作成されます –

+0

'store.createRecord'を呼び出すと(デフォルトでは)設定されていません。これはローカルでレコードを作成し、 'save()'を呼び出すとバック​​エンドにポストされます。おそらくIDを作成する特定のシリアライザを使用していますか? – nem035

答えて

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') 
    }); 
} 

export default Model.extend({ 
    order_reference: attr('string', { defaultValue: '' }) 
    // rest of the properties and their default values... 
}); 

もう一つは、代わりに空の文字列に初期化し、これらすべてのcustomerinvoiceのプロパティを作成するには、プロパティが省略された場合に追加されます燃えさしモデルのデフォルト値を定義することができます

これで、何も渡さずにレコードを作成することができます。

this.store.createRecord('customerinvoice'); 
関連する問題