Rails通过belongs_to关联获取所有对象

Don*_*n P 3 ruby-on-rails rails-activerecord

用户 has_many 问题

问题 belongs_to 用户

我怎样才能得到所有用户的问题,有自己的"标签"列等于"的Ruby-on-轨"?

如果我这样做Question.where(tag: "ruby-on-rails"),我会得到一个ActiveRecord::Relation.

如果我这样做,Question.where(tag: "ruby-on-rails").users我会收到错误undefined method 'users' for #<Question::ActiveRecord_Relation:0x007fbb96812aa0>

SHS*_*SHS 7

User.joins(:questions).where(questions: {tag: "ruby-on-rails"})
Run Code Online (Sandbox Code Playgroud)