【发布时间】:2016-06-24 20:43:50
【问题描述】:
class Question
has_many :participants, :class_name => "User"
end
class User
has_and_belongs_to_many :questions
end
现在,给定一个用户,我想查找该用户没有参与的所有问题。
类似于Question.where("participants DOES NOT INCLUDE user.id"),但实际上是有效的。我该怎么做呢?
【问题讨论】:
-
您的关系似乎应该是
has_and_belongs_to_many或has_many through关系。正如您所写的,用户应该有一个belongs_to :question关联,这没有意义——每个用户都会参与一个且只有一个问题。你能发布你的用户模型的相关部分吗? -
@RobertNubel 已更新
标签: ruby-on-rails rails-activerecord