2016-09-16 50 views
0

使用灰燼-2.6的Rails 4.2.7後端JSONAPI - 資源 - 0.8.0.beta2寶石。灰燼數據`include`使用JSONAPI不加載整個負載

我注意到,有時當我嘗試include附加資源時,它們會返回到我的有效負載中,但不會最終進入Ember存儲。然後,事實證明,取決於這些資源的代碼並不像預期的那樣運行。

那麼,爲什麼當我的有效載荷包含所有這些額外的資源時,他們不會到達Ember商店?爲什麼Ember Data沒有報告它沒有處理的有效負載元素?

回答

1

原來,我在我的Ember-Data模型中關於我的關係的聲明是使用駱駝命名的,但必須使用dasherized聲明

例如:

// Example Investment model (investment.js) 
export default DS.Model.extend({ 
    // ... 
    /** 
    * The investment can have many transactions. 
    */ 
    investmentTransactions: DS.hasMany('investmentTransactions'), 
    // ... 
}); 

...將工作在大多數情況下的罰款。然而,當試圖側向載荷(包括)我在查詢數據:

store.findRecord('investment', someId, { include: 'investment-transactions' }); 

...將帶回的投資有效載荷與所有投資交易沿着不過我灰燼的數據模型不能看到那些交易。爲了解決這個問題,我hasMany聲明需要使用一個底線轉換名稱(這也適用於您的任何belongsTo聲明):

/** 
* The investment can have many transactions. 
*/ 
investmentTransactions: DS.hasMany('investment-transactions'),