2013-02-05 87 views
0

我已經設置了一個jsFiddle證明我有努力學習Ember.js燼適配器問題

我有這些模型的問題:

App.User = DS.Model.extend({ 
    firstName: DS.attr('string'), 
    lastName: DS.attr('string'), 
    account: DS.belongsTo('App.Account') 
}); 

App.Account = DS.Model.extend({ 
    user: DS.belongsTo('App.User'), 
    transactions: DS.hasMany('App.Transaction'), 
    balance: function() { 
     return this.get('transactions').getEach('amount').reduce(function(accum, item) { 
      return accum + item; 
     }, 0); 
    }.property('[email protected]') 
}); 

App.Transaction = DS.Model.extend({ 
    account: DS.belongsTo('App.Account'), 
    amount: DS.attr('number'), 
    description: DS.attr('string') 
}); 

使用FixtureAdapter賬戶加載它的hasMany交易但不是它的belongsTo用戶。

使用RESTAdapter帳戶加載它的關係很好,但它會給出錯誤當我嘗試刪除它時太多的遞歸。

任何人都可以幫我解決這些問題嗎?謝謝:)

回答

0

我已經解決了你有FixtureAdapter的問題。您的帳戶固定裝置有user_id屬性,而不僅僅是用戶,其ID爲值。

App.Account.FIXTURES = [ 
{ 
    id: 10001, 
    user: 1, 
    transactions: [1, 2, 3] 
} 
]; 

你可以在這裏看到:http://jsfiddle.net/ianpetzer/pGeGw/

至於你與RestAdapter遇到的遞歸問題...我可能很可能是錯誤的...但我認爲這是一個錯誤燼數據。

請參見以下鏈接:

https://github.com/emberjs/data/issues/671

Infinite Loop in Ember-Data clearRelationships?