> if the column is unique-constrained, you should use find_by_column (or
> `first` with conditions or scope);
> if the column is not unique, you must use find_all_by_column (or
> alternatives);
> there's no need for an extra method.

In a world where developers never make assumptions, I'd agree with you
entirely.  However we do, and we frequently make them incorrectly.

If you believe the column (or other condition) is unique, and want to
fail-fast if you're incorrect, then you *do* need this.  Take the
following:


Status.find_by_code("cancelled")

If I build this right, and put a unique index and a NOT NULL on the
code column, you're right there's no difference.   However if I leave
off that unique index because I forgot it or mis-merged a migration
then my code will be 'randomly' returning one of the two cancelled
statuses and slowly messing up my data leaving a huge clean up job.

This to me is akin to foo.bars.create! where there are *currently* no
validations but you want exceptions rather than silent failures if you
add one later on.



-- 
Cheers

Koz

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