0

我用来ActiveModel::Serializers将 JSON 输出到 Ember.js 应用程序。我使用侧载来最大化性能。

我可以告诉ActiveModel::Serializers侧载所有PhoneNumbersSwitchboardSerializer吗?

switchboard_serializer.rb

class SwitchboardSerializer < ActiveModel::Serializer
  embed :ids, :include => true

  attributes :id, :name
  has_many :switchboard_entries
  has_many :sip_accounts, :through => :switchboard_entries
end

sip_account_serializer.rb

class SipAccountSerializer < ActiveModel::Serializer
  embed :ids, :include => true

  attributes :id, :auth_name, :caller_name, :sip_accountable_id
  has_many :phone_numbers
end
4

1 回答 1

0

通过添加has_many :phone_numbers, :through => :sip_accountsapp/models/switchboard.rb我能够使用has_many :phone_numbersin switchboard_serializer.rb。:-)

于 2013-04-03T18:41:03.523 回答