Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Practice < ActiveRecord::Base
- has_many :doctors, -> { where removed_at: nil }
- end
- class Doctor < ActiveRecord::Base
- scope :with_all_doctors, -> {includes(:practice).where.not removed_at: nil}
- belongs_to :practice
- end
- doctor = Doctor.find(id: params[:id]) #here we are fetching object hierarchy with only active doctors of practice (doctor.practice.doctors will give only active users)
- doctor = Doctor.with_all_doctors.find(id: params[:id]) #here we need to fetch object hierarchy with all doctors of practice (doctor.practice.doctors will give both active and removed doctors)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement