This project is archived and is in readonly mode.

#3359 ✓stale
Steven Hartland

Invalid SQL Generated by Mixed Relative / Qualified Conditions in ActiveRecord

Reported by Steven Hartland | October 9th, 2009 @ 11:59 AM

If you mix relative and fully qualified conditions in ActiveRecord, your in for random results with the potential for invalid SQL.

The problem lies in the base method sanitize_sql_hash_for_conditions that generates the fully qualified SQL statements. It takes a “default” table name that’s used for unqualified conditions, however it overwrites this variable if it comes across an fully qualified condition. This means that the generation of the SQL depends on the internal order of the hash resulting in unpredictable output.

The fix for this is simply to ensure that fully qualified conditions don’t overwrite the default for relative conditions, the attached patch achieves this.

More info on this issue is available here:
http://blog.multiplay.co.uk/2009/10/invalid-sql-generated-by-mixed-...

Comments and changes to this ticket

  • Rohit Arondekar

    Rohit Arondekar October 6th, 2010 @ 06:38 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>

Pages