2013-09-25 44 views
0

可以說我有這樣一個模型:不要加載的關係

App.User = DS.Model.extend({ 
     attributes : DS.attr('string'), 
     countries  : DS.hasMany('country', { async: true }), 
)}; 

,服務器返回的JSON,具有country_ids陣列,所有工作正常,但我不希望真正的負載與這些ID相對應的國家模型,這些數據是自動執行的。有什麼方法可以停止/抑制這種自動功能嗎?

回答

0

Ember數據只有在您向國家/地區輸入字段時才能加載模型。 如果您只需要id,請嘗試在模型中定義country_ids字段。

UPD:

好像*_ids由框架保留。因此,您可以讓您的服務器以另一個名稱發送此數組,並在模型中爲此定義簡單的attr。 如果使用軌道加載ActiveModel和串行::它可以這樣做:

class UserSerializer < ActiveModel::Serializer 
    embed :ids 

    attributes :id, :attributes 
    has_many :countries, key: :countries 
end 

和型號:

App.User = DS.Model.extend({ 
     attributes : DS.attr('string'), 
     countries  : DS.attr() 
)}; 
+0

這似乎是一個很好的主意,但如果我定義'countryIds:DS。 hasMany('country')'(或'country_ids')有或沒有異步我只是'countryIds.length' 0。任何想法爲什麼這可能是?我使用的是ember-data 1.0.0 canary btw。哦,謝謝你的答案btw,這真的很感激。 – Markus

+0

看到我的更新回答。希望它會有所幫助。 –