I have following associations:
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 a conference_sesssions_users
table. Admin can allow specific people to attend a particular session. So I want to form a query that whenever a user logs in and selects a conference he should be allowed to see only those sessions where the admin has allowed him to. I tried this:
scope :visibility,
lambda { |user_id| joins(:conference_sessions_users).where('conference_sessions_users.user_id = ?' => user_id) }
but I'm getting an error ActiveRecord::ConfigurationError: Association named 'conference_sessions_users' was not found on ConferenceSession; perhaps you misspelled it?
What could be wrong?