Ruby on rails 取消作用域通过联接关联取消默认作用域

Ruby on rails 取消作用域通过联接关联取消默认作用域,ruby-on-rails,ruby,activerecord,Ruby On Rails,Ruby,Activerecord,我想知道当我调用House.first.items时,如何取消范围where.not(“House.status”:deleted)。项目没有where(“House”。“status”!=deleted) 此默认范围很重要,无法将其删除。T.T尝试 class House has_many :items end class Item belongs_to :house default_scope { joins(:house}.where.not("house.status":

我想知道当我调用
House.first.items时,如何取消范围
where.not(“House.status”:deleted)
。项目
没有
where(“House”。“status”!=deleted)
此默认范围很重要,无法将其删除。T.T

尝试

class House
  has_many :items
end

class Item
  belongs_to :house
  default_scope { joins(:house}.where.not("house.status": deleted) }
end
无论如何,我很少使用
default\u范围

如果你想取消一个你能做的条件

House.first.items.unscoped
但是您必须使用散列来更改
默认\u范围
声明

House.first.items.unscope(where: [:status])

请参阅:

它将生成类似于
选择“items.”的内容*从“items”限制$1
,并且没有一些查询,还有什么其他内容吗?plzTry
unscope(where:[:status])
但是你必须用hash定义你的默认范围,而不是string
default\u范围{连接(:house}.where.not(status:deleted)}
太好了
default_scope { joins(:house}.where.not(status: deleted) }