Dado este ejemplo:
class School has_many :teachers end class Teacher belongs_to :school has_many :students end class Student belongs_to :teacher delegate :school, to: :teacher, allow_nil: true end Puedo acceder fácilmente a School con Student.first.school pero ¿cómo puedo hacerlo con JSONAPI::Serializer ?
¿Es posible tener un serializador donde sea posible student.school ?
Simplemente use una asociación indirecta en lugar de delegación:
class Student < ApplicationRecord belongs_to :teacher has_one :school, through: :teacher end class StudentSerializer include JSONAPI::Serializer has_one :school end