On 8/21/07, Ben Scofield <[EMAIL PROTECTED]> wrote:
> User.find_by(:name => "Joe", :age => 21) # better, but then why not just
> use:
>
> User.find(:all, :conditions => {:name => "Joe", :age => 21})
>
> I don't know that the hash version is noticeably easier than passing a hash
> to :conditions...
I would imagine that User.find_by(conditions_hash) is probably a
common enough usage that it's worth wrapping in a method, even if that
method's implementation is only something like:
def find_by(conditions_hash, *args)
find(:all, :conditions => conditions_hash, *args)
end
Certainly all you're saving is around ten keystrokes, but there's a
clarity benefit, and doesn't require any significant effort to
understand.
The optimisations Ben's patch provides are certainly great from a
performance point of view, but I think that Court3nay's argument still
stand; the one thing that springs to mind when I think about
dynamically-generated methods in Rails is the nightmare of debugging
routes issues - surely we should be trying to remove as much magic as
possible that isn't necessary?
--
* J *
~
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---