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
. :-)
Multilevel hasMany sideloading
-
01-04-2022 - |
Frage
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
Lösung
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow