Appropriate method for no-op AR Query chain

12 views
Skip to first unread message

jred...@salsify.com

unread,
Aug 28, 2013, 3:21:28 PM8/28/13
to rubyonra...@googlegroups.com
With Rails 3, we had a number of method-defined scopes along these lines:

def self.with_name(name)
  if name.present?
    where(name: name)
  else
    scoped
  end
end

In Rails 4, `Model#scoped` is obviously deprecated and recommends replacing with `Model#all`. But it looks like `Relation#all` is deprecated as well. What's the "right" way to do this in Rails 4?

Looking at the code and docs, the best approach I've found is to use `where(nil)` but that doesn't feel particularly idiomatic. Any better approaches?

Thanks much,
Jeremy
Reply all
Reply to author
Forward
0 new messages