Hello,  I posted this on the rails talk group but received no
response.  Perhaps someone on this list could weigh in on whether this
is expected/desired behavior or a bug that I should file and develop
failing tests for
(I doubt I have the active record method_missing fu to actually patch
it).

Test Scenario:
I would like to find or initialize a new user and base the find on the
users email address, however the user found has to also match one of
two possible 'state' values (passive || pending_singup).  While trying
to implement this I discovered that the find_or_(initialize|
create)_by_* dynamic finders totally and silently ignore any
conditions passed.

Bug?

Should'nt these dynamic finders behave the same as find_by_* or
find_all_by_* dynamic finders and use the :conditions passed to them?
The documentation seems to indicate that they should.

http://api.rubyonrails.org/classes/ActiveRecord/Base.html

Dynamic attribute-based finders documentation

"It's even possible to use all the additional parameters to find. For
example, the full interface for Payment.find_all_by_amount is actually
Payment.find_all_by_amount(amount, options). And the full interface to
Person.find_by_user_name is actually
Person.find_by_user_name(user_name, options). So you could call
Payment.find_all_by_amount(50, :order => "created_on").
The same dynamic finder style can be used to create the object if it
doesn't already exist. This dynamic finder is called with
find_or_create_by_ and will return the object if it already exists and
otherwise creates it, then returns it."

Here are a couple of examples.  I know these are contrived since I
could use 'find_or_initialize_by_name_and_state()' however what I am
really trying to show is that the :conditions options are ignored.
Check out the actual SQL run by each of these finds in a console to
see what I mean.

PASTIE w/ examples:

http://pastie.caboo.se/148479

Original Post:
http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/63ab809535b1be9d/312e09737ab18b7b?lnk=gst&q=glenn#312e09737ab18b7b

Thanks.
--~--~---------~--~----~------------~-------~--~----~
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 rubyonrails-core@googlegroups.com
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