我用来ActiveModel::Serializers
将 JSON 输出到 Ember.js 应用程序。我使用侧载来最大化性能。
我可以告诉ActiveModel::Serializers
侧载所有PhoneNumbers
的SwitchboardSerializer
吗?
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