jredburn-E0lYS+YQj7RBDgjK7y7TUQ@public.gmane.org
2013-Aug-28 19:21 UTC
Appropriate method for no-op AR Query chain
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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/b83947ae-15b9-4867-98af-f6636f6427b3%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.