Changeset 409

Show
Ignore:
Timestamp:
15.06.2006 21:40:50 (4 years ago)
Author:
hans
Message:

ticket:280 - Adding preliminary support for unique object instances. This is based roughly on Oliver's implementation outlined in wiki:Development/UniqueInstances
ticket:279 - Adding preliminary support for one-to-one relationships

Location:
trunk/generator/classes/propel/engine
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • trunk/generator/classes/propel/engine/builder/om/PeerBuilder.php

    r387 r409  
    5656                $this->addDoCount($script); 
    5757 
    58                 // consider refactoring the doSelect stuff 
    59                 // into a top-level method 
     58                // TODO - consider refactoring the doSelect stuff into a top-level method 
    6059                $this->addDoSelectOne($script); 
    6160                $this->addDoSelect($script); 
    62                 $this->addDoSelectRS($script);   // <-- there's Creole code in here 
    63                 $this->addPopulateObjects($script); // <-- there's Creole code in here 
    64  
     61                $this->addDoSelectRS($script); 
     62                $this->addGetPrimaryKeyHash($script); 
     63                $this->addPopulateObjects($script); 
    6564        } 
    6665 
  • trunk/generator/classes/propel/engine/builder/om/php5/PHP5BasicObjectBuilder.php

    r387 r409  
    321321         */ 
    322322        public function get$cfc(\$format = ".var_export($defaultfmt, true).""; 
    323                 if ($col->isLazyLoad()) $script .= ", \$con = null"; 
     323                if ($col->isLazyLoad()) $script .= ", PDO \$con = null"; 
    324324                $script .= ") 
    325325        { 
     
    373373         */ 
    374374        public function get$cfc("; 
    375                 if ($col->isLazyLoad()) $script .= "\$con = null"; 
     375                if ($col->isLazyLoad()) $script .= "PDO \$con = null"; 
    376376                $script .= ") 
    377377        { 
     
    413413         * @throws PropelException - any underlying error will be wrapped and re-thrown. 
    414414         */ 
    415         protected function load$cfc(\$con = null) 
     415        protected function load$cfc(PDO \$con = null) 
    416416        { 
    417417                \$c = \$this->buildPkeyCriteria(); 
     
    909909         * @see BaseObject::isDeleted() 
    910910         */ 
    911         public function delete(\$con = null) 
     911        public function delete(PDO \$con = null) 
    912912        { 
    913913                if (\$this->isDeleted()) { 
     
    970970         * @throws PropelException 
    971971         */ 
    972         public function save(\$con = null) 
     972        public function save(PDO \$con = null) 
    973973        { 
    974974                \$affectedRows = 0; // initialize var to track total num of affected rows 
  • trunk/generator/classes/propel/engine/builder/om/php5/PHP5BasicPeerBuilder.php

    r398 r409  
    151151                $script .= " 
    152152        /** 
     153         * An identiy map to hold any loaded instances of ".$this->getObjectClassname()." objects. 
     154         * This must be public so that other peer classes can access this when hydrating from JOIN 
     155         * queries. 
     156         * @var array ".$this->getObjectClassname()."[] 
     157         */ 
     158        public static \$instances = array(); 
     159         
     160        /** 
    153161         * The MapBuilder instance for this peer. 
    154162         * @var MapBuilder 
    155163         */ 
    156         private static \$mapBuilder = null;  
    157 "; 
    158  
     164        private static \$mapBuilder = null; 
     165         
     166"; 
     167                 
    159168                $this->addFieldNamesAttribute($script); 
    160169                $this->addFieldKeysAttribute($script); 
     
    499508         * @param object \$queryOrCriteria Query or Criteria object used to create the SELECT statement. 
    500509         * @param PDO \$con 
    501          * @return ".$this->getTable()->getPhpName()." 
     510         * @return ".$this->getObjectClassname()." 
    502511         * @throws PropelException Any exceptions caught during processing will be 
    503512         *               rethrown wrapped into a PropelException. 
     
    586595                // BasePeer returns a PDOStatement 
    587596                return ".$this->basePeerClassname."::doSelect(\$query, \$con); 
    588         }"; 
    589         } 
    590  
     597        } 
     598"; 
     599        } 
     600         
     601        /** 
     602         * Adds method to get a version of the primary key that can be used as a unique key for identifier map. 
     603         * @param string &$script The script will be modified in this method. 
     604         */ 
     605        protected function addGetPrimaryKeyHash(&$script) 
     606        { 
     607                $script .= " 
     608        /** 
     609         * Retrieves a string version of the primary key that can be used to uniquely identify a row in this table. 
     610         *  
     611         * For tables with a single-column primary key, that simple pkey value will be returned.  For tables with 
     612         * a multi-column primary key, a serialize()d version of the primary key will be returned. 
     613         *  
     614         * @param array \$row PDO resultset row. 
     615         * @param int \$startcol The 0-based offset for reading from the resultset row. 
     616         * @return string 
     617         */ 
     618        public static function getPrimaryKeyHash(\$row, \$startcol = 0) 
     619        {"; 
     620                 
     621                // We have to iterate through all the columns so that we know the offset of the primary  
     622                // key columns. 
     623                $n = 0; 
     624                foreach($this->getTable()->getColumns() as $col) { 
     625                        if(!$col->isLazyLoad()) { 
     626                                if ($col->isPrimaryKey()) { 
     627                                        $pk[] = "\$row[\$startcol + $n]"; 
     628                                } 
     629                                $n++; 
     630                        } 
     631                } 
     632                 
     633                // the general case is a single column           
     634                if (count($pk) == 1) {                                   
     635                        $script .= " 
     636                return (string) ".$pk[0].";"; 
     637                } else { 
     638                        $script .= " 
     639                return serialize(".implode(',', $pk).");";                       
     640                } 
     641                 
     642                $script .= " 
     643        } 
     644"; 
     645        } // addGetPrimaryKeyHash 
     646         
    591647        /** 
    592648         * Adds the populateObjects() method. 
     
    618674                // populate the object(s) 
    619675                while(\$row = \$stmt->fetch(PDO::FETCH_NUM)) { 
     676                        \$key = ".$this->getPeerClassname()."::getPrimaryKeyHash(\$row, 0); 
     677                        if (isset(self::\$instances[\$key])) { 
     678                                \$results[] = self::\$instances[\$key]; 
     679                        } else { 
    620680                "; 
    621681                if ($table->getChildrenColumn()) { 
    622682                        $script .= " 
    623                         // class must be set each time from the record row 
    624                         \$cls = Propel::import(".$this->getPeerClassname()."::getOMClass(\$row, 0)); 
    625                         \$obj = new \$cls(); 
    626                         \$obj->hydrate(\$row); 
    627                         \$results[] = \$obj; 
    628                         "; 
     683                                // class must be set each time from the record row 
     684                                \$cls = Propel::import(".$this->getPeerClassname()."::getOMClass(\$row, 0)); 
     685                                \$obj = new \$cls(); 
     686                                \$obj->hydrate(\$row); 
     687                                \$results[] = \$obj; 
     688                                self::\$instances[\$key] = \$obj;"; 
    629689                } else { 
    630690                        $script .= " 
    631                         \$obj = new \$cls(); 
    632                         \$obj->hydrate(\$row); 
    633                         \$results[] = \$obj; 
    634                         "; 
    635                 } 
    636                 $script .= " 
     691                                \$obj = new \$cls(); 
     692                                \$obj->hydrate(\$row); 
     693                                \$results[] = \$obj; 
     694                                self::\$instances[\$key] = \$obj;"; 
     695                } 
     696                $script .= " 
     697                        } // if key exists 
    637698                } 
    638699                return \$results; 
     
    12161277        public static function ".$this->getRetrieveMethodName()."(\$pk, PDO \$con = null) 
    12171278        { 
    1218                 if (\$con === null) { 
    1219                         \$con = Propel::getConnection(self::DATABASE_NAME); 
    1220                 } 
    1221  
    1222                 \$criteria = " .$this->getPeerClassname()."::createCriteria(); 
     1279                // shortcut to avoid calling doSelect() when we already know it's in the identity map 
     1280                \$key = (string) \$pk; 
     1281                if (isset(self::\$instances[\$key])) { 
     1282                        return self::\$instances[\$key]; 
     1283                } else { 
     1284                        if (\$con === null) { 
     1285                                \$con = Propel::getConnection(self::DATABASE_NAME); 
     1286                        } 
     1287         
     1288                        \$criteria = " .$this->getPeerClassname()."::createCriteria(); 
    12231289"; 
    12241290                $pkey = $table->getPrimaryKey(); 
    12251291                $col = array_shift($pkey); 
    12261292                $script .= " 
    1227                 \$criteria->add(new EqualExpr(".$this->getColumnConstant($col).", \$pk)); 
    1228 "; 
    1229                 $script .= " 
    1230  
    1231                 \$v = ".$this->getPeerClassname()."::doSelect(new Query(\$criteria), \$con); 
    1232  
    1233                 return !empty(\$v) > 0 ? \$v[0] : null; 
     1293                        \$criteria->add(new EqualExpr(".$this->getColumnConstant($col).", \$pk)); 
     1294"; 
     1295                $script .= " 
     1296         
     1297                        \$v = ".$this->getPeerClassname()."::doSelectOne(new Query(\$criteria), \$con); 
     1298                        if (\$v) { // only set the map, if it's an actual object 
     1299                                self::\$instances[\$key] = \$v; 
     1300                        } 
     1301                        return \$v; 
     1302                } 
    12341303        } 
    12351304"; 
     
    12981367         */ 
    12991368        public static function ".$this->getRetrieveMethodName()."("; 
    1300                 $co = 0; 
     1369                 
     1370                $params = array(); 
    13011371                foreach ($table->getPrimaryKey() as $col) { 
    13021372                        $clo = strtolower($col->getName()); 
    1303                         $script .= ($co++ ? "," : "") . " $".$clo; 
     1373                        $params[] = "\$".$clo; 
    13041374                } /* foreach */ 
    1305                 $script .= ", \$con = null) { 
    1306                 if (\$con === null) { 
    1307                         \$con = Propel::getConnection(".$this->getPeerClassname()."::DATABASE_NAME); 
    1308                 } 
    1309                 \$criteria = ".$this->getPeerClassname()."::createCriteria();"; 
     1375                 
     1376                $script .= implode(', ', $params); 
     1377                 
     1378                $script .= ", PDO \$con = null) 
     1379        { 
     1380                \$key = serialize(".implode(',',$params)."); 
     1381                if (isset(self::\$instances[\$key])) { 
     1382                        return self::\$instances[\$key]; 
     1383                } else { 
     1384                        if (\$con === null) { 
     1385                                \$con = Propel::getConnection(".$this->getPeerClassname()."::DATABASE_NAME); 
     1386                        } 
     1387                        \$criteria = ".$this->getPeerClassname()."::createCriteria();"; 
    13101388                foreach ($table->getPrimaryKey() as $col) { 
    13111389                        $clo = strtolower($col->getName()); 
    13121390                        $script .= " 
    1313                 \$criteria->add(new EqualExpr(".$this->getColumnConstant($col).", $".$clo."));"; 
    1314                 } 
    1315                 $script .= " 
    1316                 \$v = ".$this->getPeerClassname()."::doSelect(new Query(\$criteria), \$con); 
    1317  
    1318                 return !empty(\$v) ? \$v[0] : null; 
     1391                        \$criteria->add(new EqualExpr(".$this->getColumnConstant($col).", $".$clo."));"; 
     1392                } 
     1393                $script .= " 
     1394                        \$v = ".$this->getPeerClassname()."::doSelectOne(new Query(\$criteria), \$con); 
     1395                        if (\$v) { // only set the map, if it's an actual object 
     1396                                self::\$instances[\$key] = \$v; 
     1397                        } 
     1398                        return \$v; 
     1399                } 
    13191400        }"; 
    13201401        } 
     
    13361417        public static function getTableMap() 
    13371418        { 
    1338                 return Propel::getDatabaseMap(self::DATABASE_NAME)->getTable(self::TABLE_NAME); 
     1419                return Propel::getDatabaseMap(".$this->getPeerClassname()."::DATABASE_NAME)->getTable(".$this->getPeerClassname()."::TABLE_NAME); 
    13391420        } 
    13401421"; 
  • trunk/generator/classes/propel/engine/builder/om/php5/PHP5ComplexObjectBuilder.php

    r406 r409  
    375375         * @throws PropelException 
    376376         */ 
    377         public function get".$this->getFKPhpNameAffix($fk, $plural = false)."(\$con = null) 
     377        public function get".$this->getFKPhpNameAffix($fk, $plural = false)."(PDO \$con = null) 
    378378        { 
    379379                // include the related Peer class 
     
    524524         * actually need in ".$table->getPhpName().". 
    525525         */ 
    526         public function get".$relCol."Join".$relCol2."(\$criteria = null, \$con = null) 
     526        public function get".$relCol."Join".$relCol2."(Query \$query = null, PDO \$con = null) 
    527527        { 
    528528                // include the Peer class 
     
    630630        { 
    631631                foreach($this->getTable()->getReferrers() as $refFK) { 
    632                         // if ( $refFK->getTable()->getName() != $this->getTable()->getName() ) { 
     632                        // if ( $refFK->getTable()->getName() != $this->getTable()->getName() )  
     633                        if ($refFK->isLocalPrimaryKey()) { 
     634                                $this->addPKRefFKGet($script, $refFK); 
     635                        } else { 
    633636                                $this->addRefFKInit($script, $refFK); 
    634637                                $this->addRefFKGet($script, $refFK); 
     
    636639                                $this->addRefFKAdd($script, $refFK); 
    637640                                $this->addRefFKGetJoinMethods($script, $refFK); 
     641                        } 
    638642                        // } 
    639643                } 
     
    712716         * @throws PropelException 
    713717         */ 
    714         public function count$relCol(\$criteria = null, \$distinct = false, \$con = null) 
     718        public function count$relCol(Query \$query = null, \$distinct = false, \$con = null) 
    715719        { 
    716720                // include the Peer class 
     
    833837        } // addRefererGet() 
    834838 
     839        /** 
     840         * Adds the special-case method that returns a single referrer-related object, for cases 
     841         * where the foreign key columns are also the primary key of the foreign table. 
     842         *  
     843         * @param string &$script The script will be modified in this method. 
     844         */ 
     845        protected function addPKRefFKGet(&$script, ForeignKey $refFK) 
     846        { 
     847                $table = $this->getTable(); 
     848                $tblFK = $refFK->getTable(); 
     849 
     850                $fkPeerBuilder = OMBuilder::getNewPeerBuilder($refFK->getTable()); 
     851                $relCol = $this->getRefFKPhpNameAffix($refFK, $plural = false); 
     852 
     853                $collName = $this->getRefFKCollVarName($refFK); 
     854                $lastCriteriaName = $this->getRefFKLastCriteriaVarName($refFK); 
     855 
     856                $script .= " 
     857        /** 
     858         * Gets a single ".$tblFK->getName()." object, which is related in a one-to-one relationship to this object. 
     859         * @param PDO \$con 
     860         * @throws PropelException 
     861         */ 
     862        public function get$relCol(PDO \$con = null) 
     863        { 
     864                // include the Peer class 
     865                include_once '".$fkPeerBuilder->getStubPeerBuilder()->getClassFilePath()."'; 
     866";               
     867 
     868                $lfmap = $refFK->getLocalForeignMapping(); 
     869                 
     870                // remember: this object represents the foreign table, 
     871                // so we need foreign columns of the reffk to know the local columns 
     872                // that we need to set :)  
     873                  
     874                $localcols = $refFK->getForeignColumns(); 
     875                 
     876                // we know that at least every column in the primary key of the foreign table 
     877                // is represented in this foreign key 
     878                 
     879                $params = array(); 
     880                foreach ($tblFK->getPrimaryKey() as $col) { 
     881                         
     882                        $localColumn = $table->getColumn($lfmap[$col->getName()]); 
     883                        $params[] = "\$this->get".$localColumn->getPhpName()."()"; 
     884                } 
     885                         
     886                $script .= " 
     887                return ".$fkPeerBuilder->getPeerClassname()."::retrieveByPK(".implode(", ", $params).", \$con); 
     888        } 
     889"; 
     890                         
     891        } // addPKRefFKGet() 
    835892 
    836893 
     
    9941051         * @see doSave() 
    9951052         */ 
    996         public function save(\$con = null) 
     1053        public function save(PDO \$con = null) 
    9971054        { 
    9981055                if (\$this->isDeleted()) { 
  • trunk/generator/classes/propel/engine/builder/om/php5/PHP5ComplexPeerBuilder.php

    r384 r409  
    184184 
    185185                while(\$row = \$stmt->fetch(PDO::FETCH_NUM)) { 
     186                        \$key1 = ".$this->getPeerClassname()."::getPrimaryKeyHash(\$row, 0); 
     187                        if (isset(self::\$instances[\$key1])) { 
     188                                \$obj1 = self::\$instances[\$key1]; 
     189                        } else { 
    186190"; 
    187191                                                if ($table->getChildrenColumn()) { 
    188192                                                        $script .= " 
    189                         \$omClass = ".$this->getPeerClassname()."::getOMClass(\$row, 0); 
     193                                \$omClass = ".$this->getPeerClassname()."::getOMClass(\$row, 0); 
    190194"; 
    191195                                                } else { 
    192196                                                        $script .= " 
    193                         \$omClass = ".$this->getPeerClassname()."::getOMClass(); 
     197                                \$omClass = ".$this->getPeerClassname()."::getOMClass(); 
    194198"; 
    195199                                                }  
    196200                                                $script .= " 
    197                         \$cls = Propel::import(\$omClass); 
    198                         \$obj1 = new \$cls(); 
    199                         \$obj1->hydrate(\$row); 
     201                                \$cls = Propel::import(\$omClass); 
     202                                \$obj1 = new \$cls(); 
     203                                \$obj1->hydrate(\$row); 
     204                                self::\$instances[\$key1] = \$obj1; 
     205                        } // if obj1 already loaded 
     206                         
     207                        \$key2 = ".$joinedTablePeerBuilder->getPeerClassname()."::getPrimaryKeyHash(\$row, \$startcol); 
     208                        if (isset(".$joinedTablePeerBuilder->getPeerClassname()."::\$instances[\$key2])) { 
     209                                \$obj2 = ".$joinedTablePeerBuilder->getPeerClassname()."::\$instances[\$key2]; 
     210                        } else { 
    200211"; 
    201212                                                if ($joinTable->getChildrenColumn()) { 
    202213                                                        $script .= " 
    203                         \$omClass = ".$joinedTablePeerBuilder->getPeerClassname()."::getOMClass(\$row, \$startcol); 
     214                                \$omClass = ".$joinedTablePeerBuilder->getPeerClassname()."::getOMClass(\$row, \$startcol); 
    204215"; 
    205216                                                } else {  
    206217                                                        $script .= " 
    207                         \$omClass = ".$joinedTablePeerBuilder->getPeerClassname()."::getOMClass(); 
     218                                \$omClass = ".$joinedTablePeerBuilder->getPeerClassname()."::getOMClass(); 
    208219"; 
    209220                                                } 
    210221                                                 
    211222                                                $script .= " 
    212                         \$cls = Propel::import(\$omClass); 
    213                         \$obj2 = new \$cls(); 
    214                         \$obj2->hydrate(\$row, \$startcol); 
    215  
     223                                \$cls = Propel::import(\$omClass); 
     224                                \$obj2 = new \$cls(); 
     225                                \$obj2->hydrate(\$row, \$startcol); 
     226                                ".$joinedTablePeerBuilder->getPeerClassname()."::\$instances[\$key2] = \$obj2; 
     227                        } // if obj2 already loaded 
     228                         
     229                        // FIXME -- this needs to be updated for identity map 
     230                        //  
    216231                        \$newObject = true; 
    217232                        foreach(\$results as \$temp_obj1) { 
     
    338353         *               rethrown wrapped into a PropelException. 
    339354         */ 
    340         public static function doSelectJoinAll(Criteria \$c, \$con = null) 
     355        public static function doSelectJoinAll(Criteria \$c, PDO \$con = null) 
    341356        { 
    342357                \$c = clone \$c; 
     
    394409                 
    395410                while(\$row = \$stmt->fetch(PDO::FETCH_NUM)) { 
     411                        \$key1 = ".$this->getPeerClassname()."::getPrimaryKeyHash(\$row, 0); 
     412                        if (isset(self::\$instances[\$key1])) { 
     413                                \$obj1 = self::\$instances[\$key1]; 
     414                        } else { 
    396415"; 
    397416 
    398417                if ($table->getChildrenColumn()) {  
    399418                        $script .= " 
    400                         \$omClass = ".$this->getPeerClassname()."::getOMClass(\$row, 0); 
     419                                \$omClass = ".$this->getPeerClassname()."::getOMClass(\$row, 0); 
    401420"; 
    402421                } else { 
    403422                        $script .= " 
    404                         \$omClass = ".$this->getPeerClassname()."::getOMClass(); 
     423                                \$omClass = ".$this->getPeerClassname()."::getOMClass(); 
    405424"; 
    406425                } 
    407426         
    408427                $script .= " 
    409                          
    410                         \$cls = Propel::import(\$omClass); 
    411                         \$obj1 = new \$cls(); 
    412                         \$obj1->hydrate(\$row); 
     428                                 
     429                                \$cls = Propel::import(\$omClass); 
     430                                \$obj1 = new \$cls(); 
     431                                \$obj1->hydrate(\$row); 
     432                                self::\$instances[\$key1] = \$obj1; 
     433                        } // if obj1 already loaded 
    413434"; 
    414435 
     
    455476                                 
    456477                                $script .= " 
    457                                  
    458                                 // Add objects for joined $joinClassName rows 
     478                        // Add objects for joined $joinClassName rows 
     479                                                                 
     480                        \$key$index = ".$joinedTablePeerBuilder->getPeerClassname()."::getPrimaryKeyHash(\$row, \$startcol$index); 
     481                        if (isset(".$joinedTablePeerBuilder->getPeerClassname()."::\$instances[\$key$index])) { 
     482                                \$obj$index = ".$joinedTablePeerBuilder->getPeerClassname()."::\$instances[\$key$index]; 
     483                        } else {                                                                         
    459484        "; 
    460485                                if ($joinTable->getChildrenColumn()) { 
    461486                                        $script .= " 
    462                         \$omClass = ".$joinedTablePeerBuilder->getPeerClassname()."::getOMClass(\$row, \$startcol$index); 
     487                                \$omClass = ".$joinedTablePeerBuilder->getPeerClassname()."::getOMClass(\$row, \$startcol$index); 
    463488"; 
    464489                                } else { 
    465490                                        $script .= " 
    466                         \$omClass = ".$joinedTablePeerBuilder->getPeerClassname()."::getOMClass(); 
     491                                \$omClass = ".$joinedTablePeerBuilder->getPeerClassname()."::getOMClass(); 
    467492"; 
    468493                                } /* $joinTable->getChildrenColumn() */ 
    469494                         
    470495                                $script .= " 
    471          
    472                         \$cls = Propel::import(\$omClass); 
    473                         \$obj".$index." = new \$cls(); 
    474                         \$obj".$index."->hydrate(\$row, \$startcol$index); 
    475                          
     496 
     497                                \$cls = Propel::import(\$omClass); 
     498                                \$obj".$index." = new \$cls(); 
     499                                \$obj".$index."->hydrate(\$row, \$startcol$index); 
     500                                ".$joinedTablePeerBuilder->getPeerClassname()."::\$instances[\$key$index] = \$obj$index; 
     501                        } // if obj$index loaded 
     502                         
     503                        // FIXME - Fix this for new identity map system 
    476504                        \$newObject = true; 
    477505                        for (\$j=0, \$resCount=count(\$results); \$j < \$resCount; \$j++) { 
     
    522550         * @return int Number of matching rows. 
    523551         */ 
    524         public static function doCountJoinAll(Criteria \$criteria, \$distinct = false, \$con = null) 
     552        public static function doCountJoinAll(Criteria \$criteria, \$distinct = false, PDO \$con = null) 
    525553        { 
    526554                \$criteria = clone \$criteria; 
     
    628656         *               rethrown wrapped into a PropelException. 
    629657         */ 
    630         public static function doSelectJoinAllExcept".$thisTableObjectBuilder->getFKPhpNameAffix($fk, $plural = false)."(Criteria \$c, \$con = null) 
     658        public static function doSelectJoinAllExcept".$thisTableObjectBuilder->getFKPhpNameAffix($fk, $plural = false)."(Criteria \$c, PDO \$con = null) 
    631659        { 
    632660                \$c = clone \$c; 
     
    688716                 
    689717                while(\$row = \$stmt->fetch(PDO::FETCH_NUM)) { 
     718                        \$key1 = ".$this->getPeerClassname()."::getPrimaryKeyHash(\$row, 0); 
     719                        if (isset(self::\$instances[\$key1])) { 
     720                                \$obj1 = self::\$instances[\$key1]; 
     721                        } else { 
    690722"; 
    691723                        if ($table->getChildrenColumn()) { 
    692724                                $script .= " 
    693                         \$omClass = ".$this->getPeerClassname()."::getOMClass(\$row, 0); 
     725                                \$omClass = ".$this->getPeerClassname()."::getOMClass(\$row, 0); 
    694726"; 
    695727                        } else { 
    696728                                $script .= " 
    697                         \$omClass = ".$this->getPeerClassname()."::getOMClass(); 
     729                                \$omClass = ".$this->getPeerClassname()."::getOMClass(); 
    698730"; 
    699731                        } 
    700732                         
    701733                        $script .= " 
    702                         \$cls = Propel::import(\$omClass); 
    703                         \$obj1 = new \$cls(); 
    704                         \$obj1->hydrate(\$row);          
     734                                \$cls = Propel::import(\$omClass); 
     735                                \$obj1 = new \$cls(); 
     736                                \$obj1->hydrate(\$row); 
     737                                self::\$instances[\$key1] = \$obj1; 
     738                        } // if obj1 already loaded 
    705739"; 
    706740         
     
    743777                                         
    744778                                        $index++; 
    745                                  
     779 
     780                                $script .= " 
     781                        // Add objects for joined $joinClassName rows 
     782                                                                 
     783                        \$key$index = ".$joinedTablePeerBuilder->getPeerClassname()."::getPrimaryKeyHash(\$row, \$startcol$index); 
     784                        if (isset(".$joinedTablePeerBuilder->getPeerClassname()."::\$instances[\$key$index])) { 
     785                                \$obj$index = ".$joinedTablePeerBuilder->getPeerClassname()."::\$instances[\$key$index]; 
     786                        } else {                                                                         
     787"; 
    746788                                        if ($joinTable->getChildrenColumn()) { 
    747789                                                $script .= " 
    748                         \$omClass = ".$joinedTablePeerBuilder->getPeerClassname()."::getOMClass(\$row, \$startcol$index); 
     790                                \$omClass = ".$joinedTablePeerBuilder->getPeerClassname()."::getOMClass(\$row, \$startcol$index); 
    749791"; 
    750792                                        } else { 
    751793                                                $script .= " 
    752                         \$omClass = ".$joinedTablePeerBuilder->getPeerClassname()."::getOMClass(); 
     794                                \$omClass = ".$joinedTablePeerBuilder->getPeerClassname()."::getOMClass(); 
    753795"; 
    754796                                        } /* $joinTable->getChildrenColumn() */ 
    755797         
    756798                                        $script .= " 
    757          
    758                         \$cls = Propel::import(\$omClass); 
    759                         \$obj$index  = new \$cls(); 
    760                         \$obj".$index."->hydrate(\$row, \$startcol$index); 
    761                          
     799                 
     800                                \$cls = Propel::import(\$omClass); 
     801                                \$obj$index  = new \$cls(); 
     802                                \$obj".$index."->hydrate(\$row, \$startcol$index); 
     803                                ".$joinedTablePeerBuilder->getPeerClassname()."::\$instances[\$key$index] = \$obj$index; 
     804                        } // if \$obj$index already loaded 
     805                         
     806                        // FIXME - Fix this for new identity map system 
    762807                        \$newObject = true; 
    763808                        for (\$j=0, \$resCount=count(\$results); \$j < \$resCount; \$j++) { 
     
    820865         * @return int Number of matching rows. 
    821866         */ 
    822         public static function doCountJoinAllExcept".$thisTableObjectBuilder->getFKPhpNameAffix($fk, $plural = false)."(Criteria \$criteria, \$distinct = false, \$con = null) 
     867        public static function doCountJoinAllExcept".$thisTableObjectBuilder->getFKPhpNameAffix($fk, $plural = false)."(Criteria \$criteria, \$distinct = false, PDO \$con = null) 
    823868        { 
    824869                // we're going to modify criteria, so copy it first 
  • trunk/generator/classes/propel/engine/database/model/ForeignKey.php

    r371 r409  
    155155        $this->foreignTableName = $tableName; 
    156156    } 
    157  
     157         
     158        /** 
     159         * Gets the resolved foreign Table model object. 
     160         * @return Table 
     161         */ 
     162        public function getForeignTable() 
     163        { 
     164                return $this->getTable()->getDatabase()->getTable($this->getForeignTableName()); 
     165        } 
     166         
    158167    /** 
    159168     * Set the parent Table of the foreign key 
     
    254263        return $h; 
    255264    } 
    256  
     265         
     266        /** 
     267         * Whether this foreign key is also the primary key of the local table. 
     268         *  
     269         * @return boolean 
     270         */ 
     271        public function isLocalPrimaryKey() 
     272        { 
     273                $localCols = $this->getLocalColumns(); 
     274                 
     275                $localPKColumnObjs = $this->getTable()->getPrimaryKey(); 
     276                 
     277                $localPKCols = array(); 
     278                foreach($localPKColumnObjs as $lPKCol) { 
     279                        $localPKCols[] = $lPKCol->getName(); 
     280                } 
     281//               
     282//              print "Local key columns: \n"; 
     283//              print_r($localCols); 
     284//               
     285//              print "Local table primary key columns: \n"; 
     286//              print_r($localPKCols); 
     287                 
     288                return (!array_diff($localPKCols, $localCols)); 
     289        } 
     290         
    257291    /** 
    258292     * String representation of the foreign key. This is an xml representation. 
  • trunk/generator/classes/propel/engine/database/model/Table.php

    r371 r409  
    10791079     * key for this table. 
    10801080     * 
    1081      * @return array A list of the primary key parts. 
     1081     * @return array Column[] A list of the primary key parts. 
    10821082     */ 
    10831083    public function getPrimaryKey()