ruby-on-rails – Rails has_many通过where条件
发布时间:2020-12-16 21:07:46 所属栏目:百科 来源:网络整理
导读:我的Survey模型中有以下关联: has_many :survey_group_lists,- { order 'sequence ASC,group_id ASC' }has_many :groups,through: :survey_group_lists 我想添加cluase:groups association,因此它只返回活动组.我尝试过这样的事情: has_many :groups,- {
我的Survey模型中有以下关联:
has_many :survey_group_lists,-> { order 'sequence ASC,group_id ASC' } has_many :groups,through: :survey_group_lists 我想添加cluase:groups association,因此它只返回活动组.我尝试过这样的事情: has_many :groups,-> { where(active: true) },through: :survey_group_lists 但它给我一个错误: ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: missing FROM-clause entry for table "slide_groups" 我做错了什么? 编辑:我正在使用Rails 5. 解决方法
试试这个:
has_many :groups,through: :survey_group_lists,-> { where(groups: {active: true}) } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |