This project is archived and is in readonly mode.

#1405 ✓committed
Brent Miller

[PATCH] Fixed non-standard SQL generated by preloading has_and_belongs_to_many associations

Reported by Brent Miller | November 18th, 2008 @ 05:41 PM | in 2.x

This is a follow-up to ticket #394. After #394 was set to "resolved" there was discussion of another bug in the SQL that never got resolved.

The habtm :joins clause includes an extra "as" that generates non-standard SQL, causing it to break in Oracle. In INNER JOIN clauses, you can "INNER JOIN my_table t0" but you can't "INNER JOIN my_table as t0" which is the current behavior. MySQL and other dbs are tolerant of the extra "as," but Oracle throws a fit.

You can verify this with a SQL syntax checker: http://developer.mimer.com/valid...

Old output:


SELECT developers.*, t0.project_id as _parent_record_id
FROM developers
INNER JOIN developers_projects as t0 ON developers.id = t0.developer_id
WHERE (t0.project_id IN (1,2))

New output:


SELECT developers.*, t0.project_id as _parent_record_id
FROM developers
INNER JOIN developers_projects t0 ON developers.id = t0.developer_id
WHERE (t0.project_id IN (1,2))

No new tests are necessary, as no new behaviors are being added.

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

Referenced by

Pages