[Solar-svn] Revision 2751

pmjones at solarphp.com pmjones at solarphp.com
Sat Sep 8 15:01:45 CDT 2007


branch: Solar_Sql_Model: [FIX] On has-many-through eager fetching, instead of `WHERE ... IN (subquery)`, use `INNER JOIN (subquery) AS ...`.  This is because MySQL chokes on the `IN (subquery)` if the subquery has a LIMIT.  Tested, works on MySQL, PostgreSQL, and SQLite.



Modified: branches/orm/Solar/Sql/Model.php
===================================================================
--- branches/orm/Solar/Sql/Model.php	2007-09-08 19:54:29 UTC (rev 2750)
+++ branches/orm/Solar/Sql/Model.php	2007-09-08 20:01:45 UTC (rev 2751)
@@ -1396,15 +1396,13 @@
                     $spec->{$opts['native_col']} // this is where we set the filtering clause
                 );
             } else {
-                // $spec is a Select object
-                // restrict to a sub-select of IDs from the native table
-                $inner = str_replace("\n", "\n\t\t", $spec->fetchSql());
-                $select->where(
-                    "{$opts['through_alias']}.{$opts['through_native_col']} IN ($inner)"
-                );
+                // $spec is a Select object. restrict to a sub-query of IDs
+                // from the native table as an inner join.
+                $inner = str_replace("\n", "\n\t", $spec->fetchSql());
+                
                 // add the native table ID at the top through a join
-                $select->leftJoin(
-                    "{$this->_table_name} AS {$this->_model_name}",
+                $select->innerJoin(
+                    "($inner) AS {$this->_model_name}",
                     "{$opts['through_alias']}.{$opts['through_native_col']} = {$this->_model_name}.{$opts['native_col']}",
                     "{$opts['native_col']} AS {$this->_model_name}__{$opts['native_col']}"
                 );




More information about the Solar-svn mailing list