rails 3 default_scope(:where)和find

时间:2012-01-23 20:16:25

标签: ruby-on-rails-3 activerecord

查找不再导致default_scope,我现在该怎么办?我需要在很多地方找到超出默认范围的条目,我还需要在我的应用程序中为这么多列表添加作用域条目。

为什么他们改变了? :(

1 个答案:

答案 0 :(得分:1)

看看这篇文章是Rails3 here中已弃用的内容。

因此,如果您想使用不带default_scope的模型,那么您可以在下面的代码段中使用以下内容。(这是从我提到的文章中提取的)

with_scope和with_exclusive_scope

with_scope和with_exclusive_scope现在也在Relation之上实现。可以与它们使用任何关系:

with_scope(where(:name => 'lifo')) do
  ...
end

甚至使用命名范围:

with_exclusive_scope(Item.red) do
  ...
end