This project is archived and is in readonly mode.

#6464 new
Robin Wunderlin

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

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>

People watching this ticket

Attachments

Pages