Problem with addSelectQuery #232

Closed
andreme opened this Issue Dec 14, 2011 · 2 comments

Comments

Projects
None yet
2 participants

andreme commented Dec 14, 2011

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.

        $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:

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:

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

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

        $col = $qry->find();

generates:

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
Member

fzaninotto commented Dec 15, 2011

There might be a use case not managed properly in the subselect algorithm (addSelectQuery()), but before diving into it, why don't you use virtual foreign keys?

Also, to get more answers when you need supports, please use the Propel Users mailing-list instead of the Issue system - which is actuelly for bugs.

andreme commented Dec 18, 2011

Well, I think it is a bug. The only way I found to define the vitual FK's is through the xml, which we rebuild from the database. Anyway I'm not sure how this would help with joining a limited subquery?

@andreme andreme closed this Feb 8, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment