Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

146
Vistas
Rails Serializer - Access grandparent

Given this example:

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

I can easily access School with Student.first.school but how can I do it with JSONAPI::Serializer?

Is it possible to have a Serializer where student.school is possible?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Just use an indirect assocation instead of delegation:

class Student < ApplicationRecord
  belongs_to :teacher
  has_one :school, through: :teacher
end

class StudentSerializer 
  include JSONAPI::Serializer
  has_one :school
end
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda