2013-08-22 19 views
1

使用REST Adapter,可以通過做有嵌入的對象:使用嵌入對象與興業

App.Adapter.map('App.User', { 
    properties : {embedded: 'always'}, 
}); 

如何申報使用FIXTURE嵌入的對象?我已經試過在模型中指定這個:

App.User = DS.Model.extend({ 
    properties : DS.belongsTo('App.UserProperties', { embedded : true }) 
}); 

但是這不起作用。是否可以使用FIXTURES嵌入對象?我FIXTURE樣子:

App.User.FIXTURES = [ 
    { 
     id: 'id1', 
     type: 'user', 
     properties : { 
      name: 'Max Smith', 
      email: '[email protected]' } 
    }, 
]; 

回答

2

FixtureAdapter不支持嵌入式記錄,要做到這一點的唯一方法是定義FIXTURESUserProperties型號還有:

App.User.FIXTURES = [ 
    { 
    id: 'id1', 
    type: 'user', 
    properties : 1 
]; 

App.UserProperties.FIXTURES = [ 
    { 
    id: '1', 
    name: 'Max Smith', 
    email: '[email protected]' 
    } 
]; 

這裏也是一個快速的語句從@tomdale(ember-data的創建者之一)FixtureAdapter

我不相信夾具適配器支持嵌入記錄 有一個很好的理由,爲什麼它需要? 它也不支持underscored_property_names 夾具適配器的想法不是模仿來自服務器的JSON有效載荷 它提供的存根數據格式爲Ember Data期望 所以關係沒有嵌入,屬性名稱是camelCased等。

希望它有幫助。

+3

不夠公平。但是,從我的角度來看,它違背了FIXTURES的一個重要目標,即具有與後端提供的*完全相同的json,並且能夠像後端在那裏一樣測試應用程序,並具有所有已配置的映射和其他適配器配置。使用上述方法,我必須*手動*編輯json,這意味着我可以(*將*)製作錯誤。所以現在我的「測試數據」必須經過測試。不太好。 – dangonfast