【发布时间】:2023-04-03 02:15:01
【问题描述】:
模型协会
class User < ActiveRecord::Base
has_many :boards
has_many :cards, through: :boards
end
class Board < ActiveRecord::Base
belongs_to :user
has_many :cards
end
class Card < ActiveRecord::Base
belongs_to :board
end
检索记录
Card 和 Board 模型有一个称为“关闭”的属性。 在检索属于 current_user 的所有卡片时,我想过滤掉“关闭”等于 true 的板和卡片。
即
如果 board.close == true,则过滤掉该板及其所有关联卡片
如果 card.close == true,则过滤掉这张卡片
这不起作用,但显示了我正在尝试做的事情:
current_user.cards.where(card.closed == false, card.board.closed == false)
【问题讨论】:
标签: ruby-on-rails-4 activerecord has-many-through model-associations