Ember.js Don';不要加载关系

Ember.js Don';不要加载关系,ember.js,ember-data,Ember.js,Ember Data,假设我有一个这样的模型: App.User = DS.Model.extend({ attributes : DS.attr('string'), countries : DS.hasMany('country', { async: true }), )}; class UserSerializer < ActiveModel::Serializer embed :ids attributes :id, :attributes has_

假设我有一个这样的模型:

App.User = DS.Model.extend({
      attributes    : DS.attr('string'),
      countries     : DS.hasMany('country', { async: true }),
)};
class UserSerializer < ActiveModel::Serializer
  embed :ids

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

服务器返回JSON,带有
country\u id
数组,所有这些都可以正常工作,但我不想实际加载与这些id对应的country模型,余烬数据会自动加载这些模型。是否有任何方法停止/抑制此自动功能?

只有在您寻址到国家/地区字段时,才应加载模型。 若您只需要ID,请尝试在模型中定义country_ID字段

UPD:

似乎
*\u id
是由框架保留的。所以,您可以要求服务器用另一个名称发送此数组,并在模型中为此定义简单属性。 如果您使用rails和ActiveModel::Serializer,可以这样做:

App.User = DS.Model.extend({
      attributes    : DS.attr('string'),
      countries     : DS.hasMany('country', { async: true }),
)};
class UserSerializer < ActiveModel::Serializer
  embed :ids

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

这似乎是一个非常好的主意,但如果我定义带或不带async的
countryid:DS.hasMany('country')
(或
country\u id
),我只得到了
countryid.length的0。知道为什么吗?我正在使用余烬数据1.0.0金丝雀顺便说一句。哦,谢谢你的回答顺便说一句,非常感谢。