activerecord - Rails association query based on condition -
class conferencesession < activerecord::base has_many :conference_sessions end class conferencesession < activerecord::base belongs_to :conference has_and_belongs_to_many :users end class user < activerecord::base has_and_belongs_to_many :conference_sessions end
and conference_sesssions_users table. admin can allow specific people attend particular session. want form query whenever user logs in , selects conference should allowed see sessions admin has allowed him to.
i've done specific session doing
scope :visibility, lambda { |user_id| joins('inner join conference_sessions_users on conference_sessions_users.conference_session_id = conference_sessions.id'). where('conference_sessions_users.user_id = ?', user_id) }
but returns specific people, if session visible users, should condition same.
you change condition where(conference_sessions_users: { user_id: user_ids})
translate this: where conference_sessions_users.user_id in (1st_id, 2nd_id)
. of course should pass array of ids in case user_id
Comments
Post a Comment