This project is archived and is in readonly mode.

#3425 ✓stale
Dan

[PATCH] Finding records by ID and passing blank :condtions option throws ActiveRecord::StatementInvalid

Reported by Dan | October 25th, 2009 @ 02:03 PM

When trying to find a record using an ID or an array of IDs, and a blank conditions options, an incorrect SQL statement is generated (for example

Person.find 1, :conditions => []

attempts to execute the following SQL:

SELECT * FROM person WHERE (person.id = 1 AND ())

which throws ActiveRecord::StatementInvalid.

This is in contrast to other find behaviour, for example:

Person.find :all, :conditions => []

which works as expected, and returns all records.

I have attached a patch that corrects this, with tests. This is my first Rails patch so any suggestions/criticisms welcome!

Thanks,
Dan

Comments and changes to this ticket

  • Dan

    Dan October 25th, 2009 @ 02:13 PM

    • Title changed from “Finding records by ID and passing blank :condtions option throws ActiveRecord::StatementInvalid” to “[PATCH] Finding records by ID and passing blank :condtions option throws ActiveRecord::StatementInvalid”
  • Matt Jones

    Matt Jones October 26th, 2009 @ 03:35 AM

    This may be a larger design issue - there are a couple other spots (in the associations code) where this exact pattern comes up. I could see an alternative fix that sanitizes an empty :conditions array to a SQL no-op, "1=1" for instance. You may want to bring this up on rails-core.

  • Rohit Arondekar

    Rohit Arondekar October 6th, 2010 @ 06:37 AM

    • State changed from “new” to “stale”
    • Importance changed from “” to “”

    Marking ticket as stale. If this is still an issue please leave a comment with suggested changes, creating a patch with tests, rebasing an existing patch or just confirming the issue on a latest release or master/branches.

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>

Attachments

Pages