Rails has_many通过where条件

时间:2017-05-10 14:13:52

标签: ruby-on-rails ruby activerecord ruby-on-rails-5

我的调查模型中有以下关联:

has_many :groups, -> { where(active: true) }, through: :survey_group_lists

我想添加cluase to:groups association以便它只返回活动组。我尝试过这样的事情:

ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  missing FROM-clause entry for table "slide_groups"

但它给我一个错误:

{{1}}

我做错了什么?

编辑:我正在使用Rails 5。

3 个答案:

答案 0 :(得分:2)

试试这个:

display:none

答案 1 :(得分:1)

应该是:

has_many :groups, through: :survey_group_lists, -> { where(groups: { active: true } ) }

答案 2 :(得分:0)

has_many :groups, -> {where('groups.active' => true)}, through: :survey_group_lists

这是正确的。

相关问题