activerecord-hackery / squeel

Active Record, improved. Live again :)
http://erniemiller.org/2013/11/17/anyone-interested-in-activerecord-hackery/
MIT License
2.4k stars 214 forks source link

Outer join causes invalid SQL #364

Open CyborgMaster opened 9 years ago

CyborgMaster commented 9 years ago

When joining through a table, running an outer join on the intermediary table causes incorrect SQL to be emitted.

Executing the following query, without the outer join,

Reminder.joins { [~reminder_type, ~reminder_type.ext] }.select { ~reminder_type.ext.description }

gives the correct SQL with the correct table name for the description field.

SELECT `reminder_types_ext`.`description` 

However if the first table is joined with outer,

Reminder.joins { [~reminder_type.outer, ~reminder_type.ext] }.select { ~reminder_type.ext.description }

then the table name is not retrieved and it tries (incorrectly) to guess the table name from the keypath.

SELECT  `ext`.`description`

I know I could write this query as follows, which does work correctly,

Reminder.joins { [~reminder_type.outer.ext] }.select { ~reminder_type.ext.description }

but this isn't an option in my system as the query is built up from disparate parts of code each which request their own table joins and select statements. In either case the behavior isn't correct and we should fix it.

Any ideas?