Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Diffrent behaviour for find_or_create_by and find_by

#6464

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

Reported by Robin Wunderlin · February 24th, 2011 @ 12:54 PM

State: new
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Robin Wunderlin
    Robin Wunderlin
    • Tag changed from find_by find_or_create_by to find_by, find_or_create_by

    February 24th, 2011 @ 01:02 PM

  2. Jeremy Friesen
    Jeremy Friesen

    Included a patch that address the particular problem identified above.

    May 16th, 2011 @ 08:22 PM