2016-09-16 66 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'),