I have the following model
class Event < ActiveRecord::Base has_many :attendances class Attendance < ActiveRecord::Base belongs_to :user class Student < User has_one :student_detail class StudentDetail < ActiveRecord::Base belongs_to :school class Staff < User has_one :staff_detail class StaffDetail < ActiveRecord::Base
StudentDetail and StaffDetails have additional information, I try to avoid all of it in the same user STI table due to the need to work with something similar to a specific class for a table template
I can do it easy enough
Event.includes(:attendances => :user).where(...)
but I want to be able to include depending on the type of user for example.
Event.includes(attendances: {:user => :student_details })
This will fail because some of the users are Staff objects.
I understand that the rails will not support this out of the box, but who has any tricks to make it work.
The best solution right now will be shared by the user when visiting the student and staff that is.
class Attendance < ActiveRecord::Base belongs_to :student, -> {includes(:staff_detail) } belongs_to :staff, -> {includes(:student_detail) }
which is not ideal. Does anyone have any clues? way to solve this problem.
source share