class User < ApplicationRecord
has_many :user_positions
has_many :job_titles, through: :user_positions
class JobTitle < ApplicationRecord
has_many :user_positions
has_many :users, through: :user_positions
class UserPosition < ApplicationRecord
belongs_to :user
belongs_to :job_title
鉴于上述模型ActiveRecord关联,我想查询一个JOBTITLE,然后与JOBTITLE像这样返回所有用户:活动记录关联 - 错误w has_many:通过关联?
JobTitle.where(id: 6).users
这示数W¯¯
undefined method `users' for #<JobTitle::ActiveRecord_Relation
我究竟做错了什么?
感谢
'where'会给你一个ActiveRecordRelationship,许多对象,'find'会给你一个。 –