Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. class Practice < ActiveRecord::Base
  2. has_many :doctors, -> { where removed_at: nil }
  3. end
  4.  
  5. class Doctor < ActiveRecord::Base
  6. scope :with_all_doctors, -> {includes(:practice).where.not removed_at: nil}
  7. belongs_to :practice
  8. end
  9.  
  10. 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)
  11.  
  12. 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