Question

I use ActiveModel::Serializers to get JSON out to an Ember.js application. I use sideloading to maximize the performance.

Can I tell ActiveModel::Serializers to sideload all PhoneNumbers in the 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
Was it helpful?

Solution

By adding has_many :phone_numbers, :through => :sip_accounts into app/models/switchboard.rb I was able to use has_many :phone_numbers in switchboard_serializer.rb. :-)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top