propelorm/Propel — Issue #232: Problem with addSelectQuery
Author: andreme
Created: 2011-12-14 23:24:35+00:00
State: open

I'm not sure wether this is a bug or I am not using it correctly.
I have two tables I want to join, there are not FK's between them.

```php
$attendanceRecalc = \AttendanceRecalcQuery::create()->limit(400);

$qry = AttendanceQuery::create()
->addSelectQuery($attendanceRecalc, 'Re', false)
->where('Re.AttendanceID = Attendance.AttendanceID');

$qry->withColumn('Re.AttendanceRecalcID', 'RecalcID');

$col = $qry->find();
```
generates this SQL:

```SQL
SELECT Attendance.*, Re.ATTENDANCERECALCID AS RecalcID
FROM `Attendance`, `Attendance_Recalc`, (SELECT Attendance_Recalc.* FROM `Attendance_Recalc` LIMIT 400) AS Re
WHERE Re.ATTENDANCEID = Attendance.ATTENDANCEID
```
It adds Attendance_Recalc into them FROM, without any joins. I think this is a bug?

If I make the Alias the same as the Tablename it works:

```php
$qry = AttendanceQuery::create()
->addSelectQuery($attendanceRecalc, 'Attendance_Recalc', false)
->where('Attendance_Recalc.AttendanceID = Attendance.AttendanceID');

$qry->withColumn('Attendance_Recalc.AttendanceRecalcID', 'RecalcID');

$col = $qry->find();
```
generates:

```SQL
SELECT Attendance.*, Attendance_Recalc.ATTENDANCERECALCID AS RecalcID
FROM `Attendance`, (SELECT Attendance_Recalc.* FROM `Attendance_Recalc` LIMIT 400) AS Attendance_Recalc
WHERE Attendance_Recalc.ATTENDANCEID = Attendance.ATTENDANCEID
```