On Apr 15, 11:31 pm, Michael Koziarski <[email protected]> wrote:
> On 16/04/2011, at 7:54 AM, 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.
>
> > What do you think?
>
> It doesn't have backwards compatibility in terms of the values
> returned to a user, however it would have significantly difference
> performance characteristics.  Removing the limit will make the
> database examine multiple rows, lots of them in your case, which won't
> be ideal.

Replacing the LIMIT 1 with LIMIT 2 is enough to know that the
result is not "single" and I assume that change (from LIMIT 1 to
LIMIT 2) would not cause a significant performance hit on the
database performance.

Regarding backwards compatibility, I see use cases in our
project where Model.find_by_something is actually used to
find "1 random entry" from the matching rows (similar to
Model.first) and that is the expected behavior there. So,
adding the "single" condition on the current find_by_something
method would break that functionality. Therefore I propose
"find_single_by_something" as a new method to resolve this
issue.

HTH,

Peter

-- 
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.

Reply via email to