This project is archived and is in readonly mode.
Diffrent behaviour for find_or_create_by and find_by
Reported by Robin Wunderlin | February 24th, 2011 @ 12:54 PM
There is a different behaviour for "find_or_create_by" and "find_by".
If I use "EventTrack.find_by_profile_id_and_event(5)" it will
execute the SQL statement:
SELECT "event_tracks".* FROM "event_tracks" WHERE "event_tracks"."event" IS NULL AND "event_tracks"."profile_id" = 5 LIMIT 1
But if I call the method
"EventTrack.find_or_create_by_profile_id_and_event(5)" it will
execute the SQL statement:
SELECT "event_tracks".* FROM "event_tracks" WHERE "event_tracks"."profile_id" = 5 LIMIT 1
I would expect that the WHERE cause of both SQL statements would
be
WHERE "event_tracks"."event" IS NULL AND "event_tracks"."profile_id" = 5 LIMIT 1
Comments and changes to this ticket
-
Robin Wunderlin February 24th, 2011 @ 01:02 PM
- Tag changed from find_by find_or_create_by to find_by, find_or_create_by
-
Jeremy Friesen May 16th, 2011 @ 08:22 PM
Included a patch that address the particular problem identified above.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>