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