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.

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

#1405

This is a follow-up to ticket #394 [PATCH] Fixed non-standard SQL generated by preloading has_and_belongs_to_man.... After #394 [PATCH] Fixed non-standard SQL generated by preloading has_and_belongs_to_man... 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.

Reported by Brent Miller · November 18th, 2008 @ 05:41 PM

State: committed
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Repository
    Repository
    • State changed from new to committed

    (from [0c4ba90aa1ea6a8d386c724a55a31e63a13c46ab]) Removed extra 'as' in :joins clause for habtm preloading

    Signed-off-by: Michael Koziarski michael@koziarski.com

    [#1405 [PATCH] Fixed non-standard SQL generated by preloading has_and_belongs_to_man... state:committed] http://github.com/rails/rails/co...

    December 1st, 2008 @ 07:22 PM