【发布时间】:2017-03-31 07:44:09
【问题描述】:
我有以下关联:
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
还有一个conference_sesssions_users 表。管理员可以允许特定的人参加特定的会议。所以我想形成一个查询,每当用户登录并选择一个会议时,他应该被允许只看到管理员允许他看到的那些会话。我试过这个:
scope :visibility,
lambda { |user_id| joins(:conference_sessions_users).where('conference_sessions_users.user_id = ?' => user_id) }
但我收到一个错误ActiveRecord::ConfigurationError: Association named 'conference_sessions_users' was not found on ConferenceSession; perhaps you misspelled it?
可能出了什么问题?
【问题讨论】:
标签: ruby-on-rails activerecord associations has-and-belongs-to-many