On Fri, Apr 15, 2011 at 7:27 PM, Corin Langosch <[email protected]> wrote: > This change should not have any backwards compatibility issues because a > named finder with a query which selects more than one row is never desired > and a sign for bad design.
This is flatly not true. We use it all the time: customer.billings.most_recent_first.find_by_closed_at(nil) Or more explicitly: customer.billings.find_by_closed_at(nil, :order => "read_at DESC") The behavior that you want is also useful, but is a very different thing. To handle it, and similar cases when not using dynamic finders, I added a method #only on enumerable (this predates the arel method of the same name - I would choose something different now), which simply gets all results and if the size is more than one, raises an exception. So in our app we can write: customer.billings.find_all_by_closed_at(nil).only Or without anything to do with dynamic finders: customer.billings.all.only You could easily take this one step further and jack up another dynamic finder method: consumer.billings.find_only_by_closed_at(nil) But again, I would want to pick another word than 'only' now that Arel has introduced a different concept by that name. Regardless, the current find_by behavior is useful and it would not be correct to change it because there are some times when you want different behavior. -- 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.
