Tim,
I like the idea. I'd suggest :must_exist => true as another possible API.
- Jamis
Tim Lucas wrote:
> When using ActiveRecord finders that don't by throw a RecordNotFound
> exception I'm finding myself writing code like the following:
>
> def show
> @tag = Tag.find_by_name(params[:id]) or raise
> ActiveRecord::RecordNotFound
> end
>
> I don't really like the idea of raising a RecordNotFound myself, as,
> at the least, I don't get the exception message that ActiveRecord
> includes if it throws the exception internally ("Couldn't find Tag
> with ID=9999")... and it just feels... wrong.
>
> Wouldn't it be better to have a finder option to specify you want an
> exception thrown if there's no record found?
>
> def show
> @tag = Tag.find_by_name(params[:id], :throw_not_found => true)
> end
>
> Other possible APIs:
>
> :throw_if_not_found => true
> :throw_if_nil => true
> :throw_when_not_found => true
> :throw_when_nil => true
> :throw_on_not_found => true
> :throw_on_nil => true
> :not_found => :throw
>
> Thoughts?
>
> -- tim lucas
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---