class House
has_many :items
end
class Item
belongs_to :house
default_scope { joins(:house}.where.not("house.status": deleted) }
end
我想知道当我致电where.not("houses.status": deleted)
没有House.first.items
时如何取消WHERE ("houses"."status" != deleted)
取消内容
这个default_scope很重要,不能删除T.T
答案 0 :(得分:4)
尝试
House.first.items.unscoped
无论如何,我很少使用default_scope
如果你想要解决你可以做的地方
House.first.items.unscope(where: [:status])
但您必须使用哈希
更改default_scope
声明
default_scope { joins(:house}.where.not(status: deleted) }