How to do `has_one: model, through: join_model` in JSONAPI :: Resource
1 answer
In fact, you can just mention the relationship has_many
without having to mention the association through
.
So if you had this model structure:
class Teacher < ActiveRecord::Base
has_many :classrooms
has_many :students, through: :classrooms
end
class Student < ActiveRecord::Base
has_many :classrooms
has_many :teachers, through: :classrooms
end
class Classroom < ActiveRecord::Base
belongs_to :teacher
belongs_to :student
end
In your resource, Teacher
all you need is this has_many :students
.
And also in your resource Student
you will need has_many :teachers
.
+1
source to share