       1: <?php
       2:
       3: namespace Thelia\Model\om;
       4:
       5: use \BasePeer;
       6: use \Criteria;
       7: use \PDO;
       8: use \PDOStatement;
       9: use \Propel;
      10: use \PropelException;
      11: use \PropelPDO;
      12: use Thelia\Model\CategoryPeer;
      13: use Thelia\Model\ProductCategory;
      14: use Thelia\Model\ProductCategoryPeer;
      15: use Thelia\Model\ProductPeer;
      16: use Thelia\Model\map\ProductCategoryTableMap;
      17:
      18: /**
      19:  * Base static class for performing query and update operations on the 'product_category' table.
      20:  *
      21:  *
      22:  *
      23:  * @package propel.generator.Thelia.Model.om
      24:  */
      25: abstract class BaseProductCategoryPeer
      26: {
      27:
      28:     /** the default database name for this class */
      29:     const DATABASE_NAME = 'thelia';
      30:
      31:     /** the table name for this class */
      32:     const TABLE_NAME = 'product_category';
      33:
      34:     /** the related Propel class for this table */
      35:     const OM_CLASS = 'Thelia\\Model\\ProductCategory';
      36:
      37:     /** the related TableMap class for this table */
      38:     const TM_CLASS = 'ProductCategoryTableMap';
      39:
      40:     /** The total number of columns. */
      41:     const NUM_COLUMNS = 4;
      42:
      43:     /** The number of lazy-loaded columns. */
      44:     const NUM_LAZY_LOAD_COLUMNS = 0;
      45:
      46:     /** The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS) */
      47:     const NUM_HYDRATE_COLUMNS = 4;
      48:
      49:     /** the column name for the product_id field */
      50:     const PRODUCT_ID = 'product_category.product_id';
      51:
      52:     /** the column name for the category_id field */
      53:     const CATEGORY_ID = 'product_category.category_id';
      54:
      55:     /** the column name for the created_at field */
      56:     const CREATED_AT = 'product_category.created_at';
      57:
      58:     /** the column name for the updated_at field */
      59:     const UPDATED_AT = 'product_category.updated_at';
      60:
      61:     /** The default string format for model objects of the related table **/
      62:     const DEFAULT_STRING_FORMAT = 'YAML';
      63:
      64:     /**
      65:      * An identiy map to hold any loaded instances of ProductCategory objects.
      66:      * This must be public so that other peer classes can access this when hydrating from JOIN
      67:      * queries.
      68:      * @var        array ProductCategory[]
      69:      */
      70:     public static $instances = array();
      71:
      72:
      73:     /**
      74:      * holds an array of fieldnames
      75:      *
      76:      * first dimension keys are the type constants
      77:      * e.g. ProductCategoryPeer::$fieldNames[ProductCategoryPeer::TYPE_PHPNAME][0] = 'Id'
      78:      */
      79:     protected static $fieldNames = array (
      80:         BasePeer::TYPE_PHPNAME => array ('ProductId', 'CategoryId', 'CreatedAt', 'UpdatedAt', ),
      81:         BasePeer::TYPE_STUDLYPHPNAME => array ('productId', 'categoryId', 'createdAt', 'updatedAt', ),
      82:         BasePeer::TYPE_COLNAME => array (ProductCategoryPeer::PRODUCT_ID, ProductCategoryPeer::CATEGORY_ID, ProductCategoryPeer::CREATED_AT, ProductCategoryPeer::UPDATED_AT, ),
      83:         BasePeer::TYPE_RAW_COLNAME => array ('PRODUCT_ID', 'CATEGORY_ID', 'CREATED_AT', 'UPDATED_AT', ),
      84:         BasePeer::TYPE_FIELDNAME => array ('product_id', 'category_id', 'created_at', 'updated_at', ),
      85:         BasePeer::TYPE_NUM => array (0, 1, 2, 3, )
      86:     );
      87:
      88:     /**
      89:      * holds an array of keys for quick access to the fieldnames array
      90:      *
      91:      * first dimension keys are the type constants
      92:      * e.g. ProductCategoryPeer::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0
      93:      */
      94:     protected static $fieldKeys = array (
      95:         BasePeer::TYPE_PHPNAME => array ('ProductId' => 0, 'CategoryId' => 1, 'CreatedAt' => 2, 'UpdatedAt' => 3, ),
      96:         BasePeer::TYPE_STUDLYPHPNAME => array ('productId' => 0, 'categoryId' => 1, 'createdAt' => 2, 'updatedAt' => 3, ),
      97:         BasePeer::TYPE_COLNAME => array (ProductCategoryPeer::PRODUCT_ID => 0, ProductCategoryPeer::CATEGORY_ID => 1, ProductCategoryPeer::CREATED_AT => 2, ProductCategoryPeer::UPDATED_AT => 3, ),
      98:         BasePeer::TYPE_RAW_COLNAME => array ('PRODUCT_ID' => 0, 'CATEGORY_ID' => 1, 'CREATED_AT' => 2, 'UPDATED_AT' => 3, ),
      99:         BasePeer::TYPE_FIELDNAME => array ('product_id' => 0, 'category_id' => 1, 'created_at' => 2, 'updated_at' => 3, ),
     100:         BasePeer::TYPE_NUM => array (0, 1, 2, 3, )
     101:     );
     102:
     103:     /**
     104:      * Translates a fieldname to another type
     105:      *
     106:      * @param      string $name field name
     107:      * @param      string $fromType One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
     108:      *                         BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM
     109:      * @param      string $toType   One of the class type constants
     110:      * @return string          translated name of the field.
     111:      * @throws PropelException - if the specified name could not be found in the fieldname mappings.
     112:      */
     113:     public static function translateFieldName($name, $fromType, $toType)
     114:     {
     115:         $toNames = ProductCategoryPeer::getFieldNames($toType);
     116:         $key = isset(ProductCategoryPeer::$fieldKeys[$fromType][$name]) ? ProductCategoryPeer::$fieldKeys[$fromType][$name] : null;
     117:         if ($key === null) {
     118:             throw new PropelException("'$name' could not be found in the field names of type '$fromType'. These are: " . print_r(ProductCategoryPeer::$fieldKeys[$fromType], true));
     119:         }
     120:
     121:         return $toNames[$key];
     122:     }
     123:
     124:     /**
     125:      * Returns an array of field names.
     126:      *
     127:      * @param      string $type The type of fieldnames to return:
     128:      *                      One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
     129:      *                      BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM
     130:      * @return array           A list of field names
     131:      * @throws PropelException - if the type is not valid.
     132:      */
     133:     public static function getFieldNames($type = BasePeer::TYPE_PHPNAME)
     134:     {
     135:         if (!array_key_exists($type, ProductCategoryPeer::$fieldNames)) {
     136:             throw new PropelException('Method getFieldNames() expects the parameter $type to be one of the class constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. ' . $type . ' was given.');
     137:         }
     138:
     139:         return ProductCategoryPeer::$fieldNames[$type];
     140:     }
     141:
     142:     /**
     143:      * Convenience method which changes table.column to alias.column.
     144:      *
     145:      * Using this method you can maintain SQL abstraction while using column aliases.
     146:      * <code>
     147:      *      $c->addAlias("alias1", TablePeer::TABLE_NAME);
     148:      *      $c->addJoin(TablePeer::alias("alias1", TablePeer::PRIMARY_KEY_COLUMN), TablePeer::PRIMARY_KEY_COLUMN);
     149:      * </code>
     150:      * @param      string $alias The alias for the current table.
     151:      * @param      string $column The column name for current table. (i.e. ProductCategoryPeer::COLUMN_NAME).
     152:      * @return string
     153:      */
     154:     public static function alias($alias, $column)
     155:     {
     156:         return str_replace(ProductCategoryPeer::TABLE_NAME.'.', $alias.'.', $column);
     157:     }
     158:
     159:     /**
     160:      * Add all the columns needed to create a new object.
     161:      *
     162:      * Note: any columns that were marked with lazyLoad="true" in the
     163:      * XML schema will not be added to the select list and only loaded
     164:      * on demand.
     165:      *
     166:      * @param      Criteria $criteria object containing the columns to add.
     167:      * @param      string   $alias    optional table alias
     168:      * @throws PropelException Any exceptions caught during processing will be
     169:      *       rethrown wrapped into a PropelException.
     170:      */
     171:     public static function addSelectColumns(Criteria $criteria, $alias = null)
     172:     {
     173:         if (null === $alias) {
     174:             $criteria->addSelectColumn(ProductCategoryPeer::PRODUCT_ID);
     175:             $criteria->addSelectColumn(ProductCategoryPeer::CATEGORY_ID);
     176:             $criteria->addSelectColumn(ProductCategoryPeer::CREATED_AT);
     177:             $criteria->addSelectColumn(ProductCategoryPeer::UPDATED_AT);
     178:         } else {
     179:             $criteria->addSelectColumn($alias . '.product_id');
     180:             $criteria->addSelectColumn($alias . '.category_id');
     181:             $criteria->addSelectColumn($alias . '.created_at');
     182:             $criteria->addSelectColumn($alias . '.updated_at');
     183:         }
     184:     }
     185:
     186:     /**
     187:      * Returns the number of rows matching criteria.
     188:      *
     189:      * @param      Criteria $criteria
     190:      * @param      boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
     191:      * @param      PropelPDO $con
     192:      * @return int Number of matching rows.
     193:      */
     194:     public static function doCount(Criteria $criteria, $distinct = false, PropelPDO $con = null)
     195:     {
     196:         // we may modify criteria, so copy it first
     197:         $criteria = clone $criteria;
     198:
     199:         // We need to set the primary table name, since in the case that there are no WHERE columns
     200:         // it will be impossible for the BasePeer::createSelectSql() method to determine which
     201:         // tables go into the FROM clause.
     202:         $criteria->setPrimaryTableName(ProductCategoryPeer::TABLE_NAME);
     203:
     204:         if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
     205:             $criteria->setDistinct();
     206:         }
     207:
     208:         if (!$criteria->hasSelectClause()) {
     209:             ProductCategoryPeer::addSelectColumns($criteria);
     210:         }
     211:
     212:         $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
     213:         $criteria->setDbName(ProductCategoryPeer::DATABASE_NAME); // Set the correct dbName
     214:
     215:         if ($con === null) {
     216:             $con = Propel::getConnection(ProductCategoryPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     217:         }
     218:         // BasePeer returns a PDOStatement
     219:         $stmt = BasePeer::doCount($criteria, $con);
     220:
     221:         if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     222:             $count = (int) $row[0];
     223:         } else {
     224:             $count = 0; // no rows returned; we infer that means 0 matches.
     225:         }
     226:         $stmt->closeCursor();
     227:
     228:         return $count;
     229:     }
     230:     /**
     231:      * Selects one object from the DB.
     232:      *
     233:      * @param      Criteria $criteria object used to create the SELECT statement.
     234:      * @param      PropelPDO $con
     235:      * @return                 ProductCategory
     236:      * @throws PropelException Any exceptions caught during processing will be
     237:      *       rethrown wrapped into a PropelException.
     238:      */
     239:     public static function doSelectOne(Criteria $criteria, PropelPDO $con = null)
     240:     {
     241:         $critcopy = clone $criteria;
     242:         $critcopy->setLimit(1);
     243:         $objects = ProductCategoryPeer::doSelect($critcopy, $con);
     244:         if ($objects) {
     245:             return $objects[0];
     246:         }
     247:
     248:         return null;
     249:     }
     250:     /**
     251:      * Selects several row from the DB.
     252:      *
     253:      * @param      Criteria $criteria The Criteria object used to build the SELECT statement.
     254:      * @param      PropelPDO $con
     255:      * @return array           Array of selected Objects
     256:      * @throws PropelException Any exceptions caught during processing will be
     257:      *       rethrown wrapped into a PropelException.
     258:      */
     259:     public static function doSelect(Criteria $criteria, PropelPDO $con = null)
     260:     {
     261:         return ProductCategoryPeer::populateObjects(ProductCategoryPeer::doSelectStmt($criteria, $con));
     262:     }
     263:     /**
     264:      * Prepares the Criteria object and uses the parent doSelect() method to execute a PDOStatement.
     265:      *
     266:      * Use this method directly if you want to work with an executed statement directly (for example
     267:      * to perform your own object hydration).
     268:      *
     269:      * @param      Criteria $criteria The Criteria object used to build the SELECT statement.
     270:      * @param      PropelPDO $con The connection to use
     271:      * @throws PropelException Any exceptions caught during processing will be
     272:      *       rethrown wrapped into a PropelException.
     273:      * @return PDOStatement The executed PDOStatement object.
     274:      * @see        BasePeer::doSelect()
     275:      */
     276:     public static function doSelectStmt(Criteria $criteria, PropelPDO $con = null)
     277:     {
     278:         if ($con === null) {
     279:             $con = Propel::getConnection(ProductCategoryPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     280:         }
     281:
     282:         if (!$criteria->hasSelectClause()) {
     283:             $criteria = clone $criteria;
     284:             ProductCategoryPeer::addSelectColumns($criteria);
     285:         }
     286:
     287:         // Set the correct dbName
     288:         $criteria->setDbName(ProductCategoryPeer::DATABASE_NAME);
     289:
     290:         // BasePeer returns a PDOStatement
     291:         return BasePeer::doSelect($criteria, $con);
     292:     }
     293:     /**
     294:      * Adds an object to the instance pool.
     295:      *
     296:      * Propel keeps cached copies of objects in an instance pool when they are retrieved
     297:      * from the database.  In some cases -- especially when you override doSelect*()
     298:      * methods in your stub classes -- you may need to explicitly add objects
     299:      * to the cache in order to ensure that the same objects are always returned by doSelect*()
     300:      * and retrieveByPK*() calls.
     301:      *
     302:      * @param      ProductCategory $obj A ProductCategory object.
     303:      * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
     304:      */
     305:     public static function addInstanceToPool($obj, $key = null)
     306:     {
     307:         if (Propel::isInstancePoolingEnabled()) {
     308:             if ($key === null) {
     309:                 $key = serialize(array((string) $obj->getProductId(), (string) $obj->getCategoryId()));
     310:             } // if key === null
     311:             ProductCategoryPeer::$instances[$key] = $obj;
     312:         }
     313:     }
     314:
     315:     /**
     316:      * Removes an object from the instance pool.
     317:      *
     318:      * Propel keeps cached copies of objects in an instance pool when they are retrieved
     319:      * from the database.  In some cases -- especially when you override doDelete
     320:      * methods in your stub classes -- you may need to explicitly remove objects
     321:      * from the cache in order to prevent returning objects that no longer exist.
     322:      *
     323:      * @param      mixed $value A ProductCategory object or a primary key value.
     324:      *
     325:      * @return void
     326:      * @throws PropelException - if the value is invalid.
     327:      */
     328:     public static function removeInstanceFromPool($value)
     329:     {
     330:         if (Propel::isInstancePoolingEnabled() && $value !== null) {
     331:             if (is_object($value) && $value instanceof ProductCategory) {
     332:                 $key = serialize(array((string) $value->getProductId(), (string) $value->getCategoryId()));
     333:             } elseif (is_array($value) && count($value) === 2) {
     334:                 // assume we've been passed a primary key
     335:                 $key = serialize(array((string) $value[0], (string) $value[1]));
     336:             } else {
     337:                 $e = new PropelException("Invalid value passed to removeInstanceFromPool().  Expected primary key or ProductCategory object; got " . (is_object($value) ? get_class($value) . ' object.' : var_export($value,true)));
     338:                 throw $e;
     339:             }
     340:
     341:             unset(ProductCategoryPeer::$instances[$key]);
     342:         }
     343:     } // removeInstanceFromPool()
     344:
     345:     /**
     346:      * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table.
     347:      *
     348:      * For tables with a single-column primary key, that simple pkey value will be returned.  For tables with
     349:      * a multi-column primary key, a serialize()d version of the primary key will be returned.
     350:      *
     351:      * @param      string $key The key (@see getPrimaryKeyHash()) for this instance.
     352:      * @return   ProductCategory Found object or null if 1) no instance exists for specified key or 2) instance pooling has been disabled.
     353:      * @see        getPrimaryKeyHash()
     354:      */
     355:     public static function getInstanceFromPool($key)
     356:     {
     357:         if (Propel::isInstancePoolingEnabled()) {
     358:             if (isset(ProductCategoryPeer::$instances[$key])) {
     359:                 return ProductCategoryPeer::$instances[$key];
     360:             }
     361:         }
     362:
     363:         return null; // just to be explicit
     364:     }
     365:
     366:     /**
     367:      * Clear the instance pool.
     368:      *
     369:      * @return void
     370:      */
     371:     public static function clearInstancePool($and_clear_all_references = false)
     372:     {
     373:       if ($and_clear_all_references)
     374:       {
     375:         foreach (ProductCategoryPeer::$instances as $instance)
     376:         {
     377:           $instance->clearAllReferences(true);
     378:         }
     379:       }
     380:         ProductCategoryPeer::$instances = array();
     381:     }
     382:
     383:     /**
     384:      * Method to invalidate the instance pool of all tables related to product_category
     385:      * by a foreign key with ON DELETE CASCADE
     386:      */
     387:     public static function clearRelatedInstancePool()
     388:     {
     389:     }
     390:
     391:     /**
     392:      * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table.
     393:      *
     394:      * For tables with a single-column primary key, that simple pkey value will be returned.  For tables with
     395:      * a multi-column primary key, a serialize()d version of the primary key will be returned.
     396:      *
     397:      * @param      array $row PropelPDO resultset row.
     398:      * @param      int $startcol The 0-based offset for reading from the resultset row.
     399:      * @return string A string version of PK or null if the components of primary key in result array are all null.
     400:      */
     401:     public static function getPrimaryKeyHashFromRow($row, $startcol = 0)
     402:     {
     403:         // If the PK cannot be derived from the row, return null.
     404:         if ($row[$startcol] === null && $row[$startcol + 1] === null) {
     405:             return null;
     406:         }
     407:
     408:         return serialize(array((string) $row[$startcol], (string) $row[$startcol + 1]));
     409:     }
     410:
     411:     /**
     412:      * Retrieves the primary key from the DB resultset row
     413:      * For tables with a single-column primary key, that simple pkey value will be returned.  For tables with
     414:      * a multi-column primary key, an array of the primary key columns will be returned.
     415:      *
     416:      * @param      array $row PropelPDO resultset row.
     417:      * @param      int $startcol The 0-based offset for reading from the resultset row.
     418:      * @return mixed The primary key of the row
     419:      */
     420:     public static function getPrimaryKeyFromRow($row, $startcol = 0)
     421:     {
     422:
     423:         return array((int) $row[$startcol], (int) $row[$startcol + 1]);
     424:     }
     425:
     426:     /**
     427:      * The returned array will contain objects of the default type or
     428:      * objects that inherit from the default.
     429:      *
     430:      * @throws PropelException Any exceptions caught during processing will be
     431:      *       rethrown wrapped into a PropelException.
     432:      */
     433:     public static function populateObjects(PDOStatement $stmt)
     434:     {
     435:         $results = array();
     436:
     437:         // set the class once to avoid overhead in the loop
     438:         $cls = ProductCategoryPeer::getOMClass();
     439:         // populate the object(s)
     440:         while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     441:             $key = ProductCategoryPeer::getPrimaryKeyHashFromRow($row, 0);
     442:             if (null !== ($obj = ProductCategoryPeer::getInstanceFromPool($key))) {
     443:                 // We no longer rehydrate the object, since this can cause data loss.
     444:                 // See http://www.propelorm.org/ticket/509
     445:                 // $obj->hydrate($row, 0, true); // rehydrate
     446:                 $results[] = $obj;
     447:             } else {
     448:                 $obj = new $cls();
     449:                 $obj->hydrate($row);
     450:                 $results[] = $obj;
     451:                 ProductCategoryPeer::addInstanceToPool($obj, $key);
     452:             } // if key exists
     453:         }
     454:         $stmt->closeCursor();
     455:
     456:         return $results;
     457:     }
     458:     /**
     459:      * Populates an object of the default type or an object that inherit from the default.
     460:      *
     461:      * @param      array $row PropelPDO resultset row.
     462:      * @param      int $startcol The 0-based offset for reading from the resultset row.
     463:      * @throws PropelException Any exceptions caught during processing will be
     464:      *       rethrown wrapped into a PropelException.
     465:      * @return array (ProductCategory object, last column rank)
     466:      */
     467:     public static function populateObject($row, $startcol = 0)
     468:     {
     469:         $key = ProductCategoryPeer::getPrimaryKeyHashFromRow($row, $startcol);
     470:         if (null !== ($obj = ProductCategoryPeer::getInstanceFromPool($key))) {
     471:             // We no longer rehydrate the object, since this can cause data loss.
     472:             // See http://www.propelorm.org/ticket/509
     473:             // $obj->hydrate($row, $startcol, true); // rehydrate
     474:             $col = $startcol + ProductCategoryPeer::NUM_HYDRATE_COLUMNS;
     475:         } else {
     476:             $cls = ProductCategoryPeer::OM_CLASS;
     477:             $obj = new $cls();
     478:             $col = $obj->hydrate($row, $startcol);
     479:             ProductCategoryPeer::addInstanceToPool($obj, $key);
     480:         }
     481:
     482:         return array($obj, $col);
     483:     }
     484:
     485:
     486:     /**
     487:      * Returns the number of rows matching criteria, joining the related Product table
     488:      *
     489:      * @param      Criteria $criteria
     490:      * @param      boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
     491:      * @param      PropelPDO $con
     492:      * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
     493:      * @return int Number of matching rows.
     494:      */
     495:     public static function doCountJoinProduct(Criteria $criteria, $distinct = false, PropelPDO $con = null, $join_behavior = Criteria::LEFT_JOIN)
     496:     {
     497:         // we're going to modify criteria, so copy it first
     498:         $criteria = clone $criteria;
     499:
     500:         // We need to set the primary table name, since in the case that there are no WHERE columns
     501:         // it will be impossible for the BasePeer::createSelectSql() method to determine which
     502:         // tables go into the FROM clause.
     503:         $criteria->setPrimaryTableName(ProductCategoryPeer::TABLE_NAME);
     504:
     505:         if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
     506:             $criteria->setDistinct();
     507:         }
     508:
     509:         if (!$criteria->hasSelectClause()) {
     510:             ProductCategoryPeer::addSelectColumns($criteria);
     511:         }
     512:
     513:         $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
     514:
     515:         // Set the correct dbName
     516:         $criteria->setDbName(ProductCategoryPeer::DATABASE_NAME);
     517:
     518:         if ($con === null) {
     519:             $con = Propel::getConnection(ProductCategoryPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     520:         }
     521:
     522:         $criteria->addJoin(ProductCategoryPeer::PRODUCT_ID, ProductPeer::ID, $join_behavior);
     523:
     524:         $stmt = BasePeer::doCount($criteria, $con);
     525:
     526:         if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     527:             $count = (int) $row[0];
     528:         } else {
     529:             $count = 0; // no rows returned; we infer that means 0 matches.
     530:         }
     531:         $stmt->closeCursor();
     532:
     533:         return $count;
     534:     }
     535:
     536:
     537:     /**
     538:      * Returns the number of rows matching criteria, joining the related Category table
     539:      *
     540:      * @param      Criteria $criteria
     541:      * @param      boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
     542:      * @param      PropelPDO $con
     543:      * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
     544:      * @return int Number of matching rows.
     545:      */
     546:     public static function doCountJoinCategory(Criteria $criteria, $distinct = false, PropelPDO $con = null, $join_behavior = Criteria::LEFT_JOIN)
     547:     {
     548:         // we're going to modify criteria, so copy it first
     549:         $criteria = clone $criteria;
     550:
     551:         // We need to set the primary table name, since in the case that there are no WHERE columns
     552:         // it will be impossible for the BasePeer::createSelectSql() method to determine which
     553:         // tables go into the FROM clause.
     554:         $criteria->setPrimaryTableName(ProductCategoryPeer::TABLE_NAME);
     555:
     556:         if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
     557:             $criteria->setDistinct();
     558:         }
     559:
     560:         if (!$criteria->hasSelectClause()) {
     561:             ProductCategoryPeer::addSelectColumns($criteria);
     562:         }
     563:
     564:         $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
     565:
     566:         // Set the correct dbName
     567:         $criteria->setDbName(ProductCategoryPeer::DATABASE_NAME);
     568:
     569:         if ($con === null) {
     570:             $con = Propel::getConnection(ProductCategoryPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     571:         }
     572:
     573:         $criteria->addJoin(ProductCategoryPeer::CATEGORY_ID, CategoryPeer::ID, $join_behavior);
     574:
     575:         $stmt = BasePeer::doCount($criteria, $con);
     576:
     577:         if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     578:             $count = (int) $row[0];
     579:         } else {
     580:             $count = 0; // no rows returned; we infer that means 0 matches.
     581:         }
     582:         $stmt->closeCursor();
     583:
     584:         return $count;
     585:     }
     586:
     587:
     588:     /**
     589:      * Selects a collection of ProductCategory objects pre-filled with their Product objects.
     590:      * @param      Criteria  $criteria
     591:      * @param      PropelPDO $con
     592:      * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
     593:      * @return array           Array of ProductCategory objects.
     594:      * @throws PropelException Any exceptions caught during processing will be
     595:      *       rethrown wrapped into a PropelException.
     596:      */
     597:     public static function doSelectJoinProduct(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
     598:     {
     599:         $criteria = clone $criteria;
     600:
     601:         // Set the correct dbName if it has not been overridden
     602:         if ($criteria->getDbName() == Propel::getDefaultDB()) {
     603:             $criteria->setDbName(ProductCategoryPeer::DATABASE_NAME);
     604:         }
     605:
     606:         ProductCategoryPeer::addSelectColumns($criteria);
     607:         $startcol = ProductCategoryPeer::NUM_HYDRATE_COLUMNS;
     608:         ProductPeer::addSelectColumns($criteria);
     609:
     610:         $criteria->addJoin(ProductCategoryPeer::PRODUCT_ID, ProductPeer::ID, $join_behavior);
     611:
     612:         $stmt = BasePeer::doSelect($criteria, $con);
     613:         $results = array();
     614:
     615:         while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     616:             $key1 = ProductCategoryPeer::getPrimaryKeyHashFromRow($row, 0);
     617:             if (null !== ($obj1 = ProductCategoryPeer::getInstanceFromPool($key1))) {
     618:                 // We no longer rehydrate the object, since this can cause data loss.
     619:                 // See http://www.propelorm.org/ticket/509
     620:                 // $obj1->hydrate($row, 0, true); // rehydrate
     621:             } else {
     622:
     623:                 $cls = ProductCategoryPeer::getOMClass();
     624:
     625:                 $obj1 = new $cls();
     626:                 $obj1->hydrate($row);
     627:                 ProductCategoryPeer::addInstanceToPool($obj1, $key1);
     628:             } // if $obj1 already loaded
     629:
     630:             $key2 = ProductPeer::getPrimaryKeyHashFromRow($row, $startcol);
     631:             if ($key2 !== null) {
     632:                 $obj2 = ProductPeer::getInstanceFromPool($key2);
     633:                 if (!$obj2) {
     634:
     635:                     $cls = ProductPeer::getOMClass();
     636:
     637:                     $obj2 = new $cls();
     638:                     $obj2->hydrate($row, $startcol);
     639:                     ProductPeer::addInstanceToPool($obj2, $key2);
     640:                 } // if obj2 already loaded
     641:
     642:                 // Add the $obj1 (ProductCategory) to $obj2 (Product)
     643:                 $obj2->addProductCategory($obj1);
     644:
     645:             } // if joined row was not null
     646:
     647:             $results[] = $obj1;
     648:         }
     649:         $stmt->closeCursor();
     650:
     651:         return $results;
     652:     }
     653:
     654:
     655:     /**
     656:      * Selects a collection of ProductCategory objects pre-filled with their Category objects.
     657:      * @param      Criteria  $criteria
     658:      * @param      PropelPDO $con
     659:      * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
     660:      * @return array           Array of ProductCategory objects.
     661:      * @throws PropelException Any exceptions caught during processing will be
     662:      *       rethrown wrapped into a PropelException.
     663:      */
     664:     public static function doSelectJoinCategory(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
     665:     {
     666:         $criteria = clone $criteria;
     667:
     668:         // Set the correct dbName if it has not been overridden
     669:         if ($criteria->getDbName() == Propel::getDefaultDB()) {
     670:             $criteria->setDbName(ProductCategoryPeer::DATABASE_NAME);
     671:         }
     672:
     673:         ProductCategoryPeer::addSelectColumns($criteria);
     674:         $startcol = ProductCategoryPeer::NUM_HYDRATE_COLUMNS;
     675:         CategoryPeer::addSelectColumns($criteria);
     676:
     677:         $criteria->addJoin(ProductCategoryPeer::CATEGORY_ID, CategoryPeer::ID, $join_behavior);
     678:
     679:         $stmt = BasePeer::doSelect($criteria, $con);
     680:         $results = array();
     681:
     682:         while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     683:             $key1 = ProductCategoryPeer::getPrimaryKeyHashFromRow($row, 0);
     684:             if (null !== ($obj1 = ProductCategoryPeer::getInstanceFromPool($key1))) {
     685:                 // We no longer rehydrate the object, since this can cause data loss.
     686:                 // See http://www.propelorm.org/ticket/509
     687:                 // $obj1->hydrate($row, 0, true); // rehydrate
     688:             } else {
     689:
     690:                 $cls = ProductCategoryPeer::getOMClass();
     691:
     692:                 $obj1 = new $cls();
     693:                 $obj1->hydrate($row);
     694:                 ProductCategoryPeer::addInstanceToPool($obj1, $key1);
     695:             } // if $obj1 already loaded
     696:
     697:             $key2 = CategoryPeer::getPrimaryKeyHashFromRow($row, $startcol);
     698:             if ($key2 !== null) {
     699:                 $obj2 = CategoryPeer::getInstanceFromPool($key2);
     700:                 if (!$obj2) {
     701:
     702:                     $cls = CategoryPeer::getOMClass();
     703:
     704:                     $obj2 = new $cls();
     705:                     $obj2->hydrate($row, $startcol);
     706:                     CategoryPeer::addInstanceToPool($obj2, $key2);
     707:                 } // if obj2 already loaded
     708:
     709:                 // Add the $obj1 (ProductCategory) to $obj2 (Category)
     710:                 $obj2->addProductCategory($obj1);
     711:
     712:             } // if joined row was not null
     713:
     714:             $results[] = $obj1;
     715:         }
     716:         $stmt->closeCursor();
     717:
     718:         return $results;
     719:     }
     720:
     721:
     722:     /**
     723:      * Returns the number of rows matching criteria, joining all related tables
     724:      *
     725:      * @param      Criteria $criteria
     726:      * @param      boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
     727:      * @param      PropelPDO $con
     728:      * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
     729:      * @return int Number of matching rows.
     730:      */
     731:     public static function doCountJoinAll(Criteria $criteria, $distinct = false, PropelPDO $con = null, $join_behavior = Criteria::LEFT_JOIN)
     732:     {
     733:         // we're going to modify criteria, so copy it first
     734:         $criteria = clone $criteria;
     735:
     736:         // We need to set the primary table name, since in the case that there are no WHERE columns
     737:         // it will be impossible for the BasePeer::createSelectSql() method to determine which
     738:         // tables go into the FROM clause.
     739:         $criteria->setPrimaryTableName(ProductCategoryPeer::TABLE_NAME);
     740:
     741:         if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
     742:             $criteria->setDistinct();
     743:         }
     744:
     745:         if (!$criteria->hasSelectClause()) {
     746:             ProductCategoryPeer::addSelectColumns($criteria);
     747:         }
     748:
     749:         $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
     750:
     751:         // Set the correct dbName
     752:         $criteria->setDbName(ProductCategoryPeer::DATABASE_NAME);
     753:
     754:         if ($con === null) {
     755:             $con = Propel::getConnection(ProductCategoryPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     756:         }
     757:
     758:         $criteria->addJoin(ProductCategoryPeer::PRODUCT_ID, ProductPeer::ID, $join_behavior);
     759:
     760:         $criteria->addJoin(ProductCategoryPeer::CATEGORY_ID, CategoryPeer::ID, $join_behavior);
     761:
     762:         $stmt = BasePeer::doCount($criteria, $con);
     763:
     764:         if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     765:             $count = (int) $row[0];
     766:         } else {
     767:             $count = 0; // no rows returned; we infer that means 0 matches.
     768:         }
     769:         $stmt->closeCursor();
     770:
     771:         return $count;
     772:     }
     773:
     774:     /**
     775:      * Selects a collection of ProductCategory objects pre-filled with all related objects.
     776:      *
     777:      * @param      Criteria  $criteria
     778:      * @param      PropelPDO $con
     779:      * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
     780:      * @return array           Array of ProductCategory objects.
     781:      * @throws PropelException Any exceptions caught during processing will be
     782:      *       rethrown wrapped into a PropelException.
     783:      */
     784:     public static function doSelectJoinAll(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
     785:     {
     786:         $criteria = clone $criteria;
     787:
     788:         // Set the correct dbName if it has not been overridden
     789:         if ($criteria->getDbName() == Propel::getDefaultDB()) {
     790:             $criteria->setDbName(ProductCategoryPeer::DATABASE_NAME);
     791:         }
     792:
     793:         ProductCategoryPeer::addSelectColumns($criteria);
     794:         $startcol2 = ProductCategoryPeer::NUM_HYDRATE_COLUMNS;
     795:
     796:         ProductPeer::addSelectColumns($criteria);
     797:         $startcol3 = $startcol2 + ProductPeer::NUM_HYDRATE_COLUMNS;
     798:
     799:         CategoryPeer::addSelectColumns($criteria);
     800:         $startcol4 = $startcol3 + CategoryPeer::NUM_HYDRATE_COLUMNS;
     801:
     802:         $criteria->addJoin(ProductCategoryPeer::PRODUCT_ID, ProductPeer::ID, $join_behavior);
     803:
     804:         $criteria->addJoin(ProductCategoryPeer::CATEGORY_ID, CategoryPeer::ID, $join_behavior);
     805:
     806:         $stmt = BasePeer::doSelect($criteria, $con);
     807:         $results = array();
     808:
     809:         while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     810:             $key1 = ProductCategoryPeer::getPrimaryKeyHashFromRow($row, 0);
     811:             if (null !== ($obj1 = ProductCategoryPeer::getInstanceFromPool($key1))) {
     812:                 // We no longer rehydrate the object, since this can cause data loss.
     813:                 // See http://www.propelorm.org/ticket/509
     814:                 // $obj1->hydrate($row, 0, true); // rehydrate
     815:             } else {
     816:                 $cls = ProductCategoryPeer::getOMClass();
     817:
     818:                 $obj1 = new $cls();
     819:                 $obj1->hydrate($row);
     820:                 ProductCategoryPeer::addInstanceToPool($obj1, $key1);
     821:             } // if obj1 already loaded
     822:
     823:             // Add objects for joined Product rows
     824:
     825:             $key2 = ProductPeer::getPrimaryKeyHashFromRow($row, $startcol2);
     826:             if ($key2 !== null) {
     827:                 $obj2 = ProductPeer::getInstanceFromPool($key2);
     828:                 if (!$obj2) {
     829:
     830:                     $cls = ProductPeer::getOMClass();
     831:
     832:                     $obj2 = new $cls();
     833:                     $obj2->hydrate($row, $startcol2);
     834:                     ProductPeer::addInstanceToPool($obj2, $key2);
     835:                 } // if obj2 loaded
     836:
     837:                 // Add the $obj1 (ProductCategory) to the collection in $obj2 (Product)
     838:                 $obj2->addProductCategory($obj1);
     839:             } // if joined row not null
     840:
     841:             // Add objects for joined Category rows
     842:
     843:             $key3 = CategoryPeer::getPrimaryKeyHashFromRow($row, $startcol3);
     844:             if ($key3 !== null) {
     845:                 $obj3 = CategoryPeer::getInstanceFromPool($key3);
     846:                 if (!$obj3) {
     847:
     848:                     $cls = CategoryPeer::getOMClass();
     849:
     850:                     $obj3 = new $cls();
     851:                     $obj3->hydrate($row, $startcol3);
     852:                     CategoryPeer::addInstanceToPool($obj3, $key3);
     853:                 } // if obj3 loaded
     854:
     855:                 // Add the $obj1 (ProductCategory) to the collection in $obj3 (Category)
     856:                 $obj3->addProductCategory($obj1);
     857:             } // if joined row not null
     858:
     859:             $results[] = $obj1;
     860:         }
     861:         $stmt->closeCursor();
     862:
     863:         return $results;
     864:     }
     865:
     866:
     867:     /**
     868:      * Returns the number of rows matching criteria, joining the related Product table
     869:      *
     870:      * @param      Criteria $criteria
     871:      * @param      boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
     872:      * @param      PropelPDO $con
     873:      * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
     874:      * @return int Number of matching rows.
     875:      */
     876:     public static function doCountJoinAllExceptProduct(Criteria $criteria, $distinct = false, PropelPDO $con = null, $join_behavior = Criteria::LEFT_JOIN)
     877:     {
     878:         // we're going to modify criteria, so copy it first
     879:         $criteria = clone $criteria;
     880:
     881:         // We need to set the primary table name, since in the case that there are no WHERE columns
     882:         // it will be impossible for the BasePeer::createSelectSql() method to determine which
     883:         // tables go into the FROM clause.
     884:         $criteria->setPrimaryTableName(ProductCategoryPeer::TABLE_NAME);
     885:
     886:         if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
     887:             $criteria->setDistinct();
     888:         }
     889:
     890:         if (!$criteria->hasSelectClause()) {
     891:             ProductCategoryPeer::addSelectColumns($criteria);
     892:         }
     893:
     894:         $criteria->clearOrderByColumns(); // ORDER BY should not affect count
     895:
     896:         // Set the correct dbName
     897:         $criteria->setDbName(ProductCategoryPeer::DATABASE_NAME);
     898:
     899:         if ($con === null) {
     900:             $con = Propel::getConnection(ProductCategoryPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     901:         }
     902:
     903:         $criteria->addJoin(ProductCategoryPeer::CATEGORY_ID, CategoryPeer::ID, $join_behavior);
     904:
     905:         $stmt = BasePeer::doCount($criteria, $con);
     906:
     907:         if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     908:             $count = (int) $row[0];
     909:         } else {
     910:             $count = 0; // no rows returned; we infer that means 0 matches.
     911:         }
     912:         $stmt->closeCursor();
     913:
     914:         return $count;
     915:     }
     916:
     917:
     918:     /**
     919:      * Returns the number of rows matching criteria, joining the related Category table
     920:      *
     921:      * @param      Criteria $criteria
     922:      * @param      boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
     923:      * @param      PropelPDO $con
     924:      * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
     925:      * @return int Number of matching rows.
     926:      */
     927:     public static function doCountJoinAllExceptCategory(Criteria $criteria, $distinct = false, PropelPDO $con = null, $join_behavior = Criteria::LEFT_JOIN)
     928:     {
     929:         // we're going to modify criteria, so copy it first
     930:         $criteria = clone $criteria;
     931:
     932:         // We need to set the primary table name, since in the case that there are no WHERE columns
     933:         // it will be impossible for the BasePeer::createSelectSql() method to determine which
     934:         // tables go into the FROM clause.
     935:         $criteria->setPrimaryTableName(ProductCategoryPeer::TABLE_NAME);
     936:
     937:         if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
     938:             $criteria->setDistinct();
     939:         }
     940:
     941:         if (!$criteria->hasSelectClause()) {
     942:             ProductCategoryPeer::addSelectColumns($criteria);
     943:         }
     944:
     945:         $criteria->clearOrderByColumns(); // ORDER BY should not affect count
     946:
     947:         // Set the correct dbName
     948:         $criteria->setDbName(ProductCategoryPeer::DATABASE_NAME);
     949:
     950:         if ($con === null) {
     951:             $con = Propel::getConnection(ProductCategoryPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     952:         }
     953:
     954:         $criteria->addJoin(ProductCategoryPeer::PRODUCT_ID, ProductPeer::ID, $join_behavior);
     955:
     956:         $stmt = BasePeer::doCount($criteria, $con);
     957:
     958:         if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     959:             $count = (int) $row[0];
     960:         } else {
     961:             $count = 0; // no rows returned; we infer that means 0 matches.
     962:         }
     963:         $stmt->closeCursor();
     964:
     965:         return $count;
     966:     }
     967:
     968:
     969:     /**
     970:      * Selects a collection of ProductCategory objects pre-filled with all related objects except Product.
     971:      *
     972:      * @param      Criteria  $criteria
     973:      * @param      PropelPDO $con
     974:      * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
     975:      * @return array           Array of ProductCategory objects.
     976:      * @throws PropelException Any exceptions caught during processing will be
     977:      *       rethrown wrapped into a PropelException.
     978:      */
     979:     public static function doSelectJoinAllExceptProduct(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
     980:     {
     981:         $criteria = clone $criteria;
     982:
     983:         // Set the correct dbName if it has not been overridden
     984:         // $criteria->getDbName() will return the same object if not set to another value
     985:         // so == check is okay and faster
     986:         if ($criteria->getDbName() == Propel::getDefaultDB()) {
     987:             $criteria->setDbName(ProductCategoryPeer::DATABASE_NAME);
     988:         }
     989:
     990:         ProductCategoryPeer::addSelectColumns($criteria);
     991:         $startcol2 = ProductCategoryPeer::NUM_HYDRATE_COLUMNS;
     992:
     993:         CategoryPeer::addSelectColumns($criteria);
     994:         $startcol3 = $startcol2 + CategoryPeer::NUM_HYDRATE_COLUMNS;
     995:
     996:         $criteria->addJoin(ProductCategoryPeer::CATEGORY_ID, CategoryPeer::ID, $join_behavior);
     997:
     998:
     999:         $stmt = BasePeer::doSelect($criteria, $con);
    1000:         $results = array();
    1001:
    1002:         while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
    1003:             $key1 = ProductCategoryPeer::getPrimaryKeyHashFromRow($row, 0);
    1004:             if (null !== ($obj1 = ProductCategoryPeer::getInstanceFromPool($key1))) {
    1005:                 // We no longer rehydrate the object, since this can cause data loss.
    1006:                 // See http://www.propelorm.org/ticket/509
    1007:                 // $obj1->hydrate($row, 0, true); // rehydrate
    1008:             } else {
    1009:                 $cls = ProductCategoryPeer::getOMClass();
    1010:
    1011:                 $obj1 = new $cls();
    1012:                 $obj1->hydrate($row);
    1013:                 ProductCategoryPeer::addInstanceToPool($obj1, $key1);
    1014:             } // if obj1 already loaded
    1015:
    1016:                 // Add objects for joined Category rows
    1017:
    1018:                 $key2 = CategoryPeer::getPrimaryKeyHashFromRow($row, $startcol2);
    1019:                 if ($key2 !== null) {
    1020:                     $obj2 = CategoryPeer::getInstanceFromPool($key2);
    1021:                     if (!$obj2) {
    1022:
    1023:                         $cls = CategoryPeer::getOMClass();
    1024:
    1025:                     $obj2 = new $cls();
    1026:                     $obj2->hydrate($row, $startcol2);
    1027:                     CategoryPeer::addInstanceToPool($obj2, $key2);
    1028:                 } // if $obj2 already loaded
    1029:
    1030:                 // Add the $obj1 (ProductCategory) to the collection in $obj2 (Category)
    1031:                 $obj2->addProductCategory($obj1);
    1032:
    1033:             } // if joined row is not null
    1034:
    1035:             $results[] = $obj1;
    1036:         }
    1037:         $stmt->closeCursor();
    1038:
    1039:         return $results;
    1040:     }
    1041:
    1042:
    1043:     /**
    1044:      * Selects a collection of ProductCategory objects pre-filled with all related objects except Category.
    1045:      *
    1046:      * @param      Criteria  $criteria
    1047:      * @param      PropelPDO $con
    1048:      * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
    1049:      * @return array           Array of ProductCategory objects.
    1050:      * @throws PropelException Any exceptions caught during processing will be
    1051:      *       rethrown wrapped into a PropelException.
    1052:      */
    1053:     public static function doSelectJoinAllExceptCategory(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
    1054:     {
    1055:         $criteria = clone $criteria;
    1056:
    1057:         // Set the correct dbName if it has not been overridden
    1058:         // $criteria->getDbName() will return the same object if not set to another value
    1059:         // so == check is okay and faster
    1060:         if ($criteria->getDbName() == Propel::getDefaultDB()) {
    1061:             $criteria->setDbName(ProductCategoryPeer::DATABASE_NAME);
    1062:         }
    1063:
    1064:         ProductCategoryPeer::addSelectColumns($criteria);
    1065:         $startcol2 = ProductCategoryPeer::NUM_HYDRATE_COLUMNS;
    1066:
    1067:         ProductPeer::addSelectColumns($criteria);
    1068:         $startcol3 = $startcol2 + ProductPeer::NUM_HYDRATE_COLUMNS;
    1069:
    1070:         $criteria->addJoin(ProductCategoryPeer::PRODUCT_ID, ProductPeer::ID, $join_behavior);
    1071:
    1072:
    1073:         $stmt = BasePeer::doSelect($criteria, $con);
    1074:         $results = array();
    1075:
    1076:         while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
    1077:             $key1 = ProductCategoryPeer::getPrimaryKeyHashFromRow($row, 0);
    1078:             if (null !== ($obj1 = ProductCategoryPeer::getInstanceFromPool($key1))) {
    1079:                 // We no longer rehydrate the object, since this can cause data loss.
    1080:                 // See http://www.propelorm.org/ticket/509
    1081:                 // $obj1->hydrate($row, 0, true); // rehydrate
    1082:             } else {
    1083:                 $cls = ProductCategoryPeer::getOMClass();
    1084:
    1085:                 $obj1 = new $cls();
    1086:                 $obj1->hydrate($row);
    1087:                 ProductCategoryPeer::addInstanceToPool($obj1, $key1);
    1088:             } // if obj1 already loaded
    1089:
    1090:                 // Add objects for joined Product rows
    1091:
    1092:                 $key2 = ProductPeer::getPrimaryKeyHashFromRow($row, $startcol2);
    1093:                 if ($key2 !== null) {
    1094:                     $obj2 = ProductPeer::getInstanceFromPool($key2);
    1095:                     if (!$obj2) {
    1096:
    1097:                         $cls = ProductPeer::getOMClass();
    1098:
    1099:                     $obj2 = new $cls();
    1100:                     $obj2->hydrate($row, $startcol2);
    1101:                     ProductPeer::addInstanceToPool($obj2, $key2);
    1102:                 } // if $obj2 already loaded
    1103:
    1104:                 // Add the $obj1 (ProductCategory) to the collection in $obj2 (Product)
    1105:                 $obj2->addProductCategory($obj1);
    1106:
    1107:             } // if joined row is not null
    1108:
    1109:             $results[] = $obj1;
    1110:         }
    1111:         $stmt->closeCursor();
    1112:
    1113:         return $results;
    1114:     }
    1115:
    1116:     /**
    1117:      * Returns the TableMap related to this peer.
    1118:      * This method is not needed for general use but a specific application could have a need.
    1119:      * @return TableMap
    1120:      * @throws PropelException Any exceptions caught during processing will be
    1121:      *       rethrown wrapped into a PropelException.
    1122:      */
    1123:     public static function getTableMap()
    1124:     {
    1125:         return Propel::getDatabaseMap(ProductCategoryPeer::DATABASE_NAME)->getTable(ProductCategoryPeer::TABLE_NAME);
    1126:     }
    1127:
    1128:     /**
    1129:      * Add a TableMap instance to the database for this peer class.
    1130:      */
    1131:     public static function buildTableMap()
    1132:     {
    1133:       $dbMap = Propel::getDatabaseMap(BaseProductCategoryPeer::DATABASE_NAME);
    1134:       if (!$dbMap->hasTable(BaseProductCategoryPeer::TABLE_NAME)) {
    1135:         $dbMap->addTableObject(new ProductCategoryTableMap());
    1136:       }
    1137:     }
    1138:
    1139:     /**
    1140:      * The class that the Peer will make instances of.
    1141:      *
    1142:      *
    1143:      * @return string ClassName
    1144:      */
    1145:     public static function getOMClass($row = 0, $colnum = 0)
    1146:     {
    1147:         return ProductCategoryPeer::OM_CLASS;
    1148:     }
    1149:
    1150:     /**
    1151:      * Performs an INSERT on the database, given a ProductCategory or Criteria object.
    1152:      *
    1153:      * @param      mixed $values Criteria or ProductCategory object containing data that is used to create the INSERT statement.
    1154:      * @param      PropelPDO $con the PropelPDO connection to use
    1155:      * @return mixed           The new primary key.
    1156:      * @throws PropelException Any exceptions caught during processing will be
    1157:      *       rethrown wrapped into a PropelException.
    1158:      */
    1159:     public static function doInsert($values, PropelPDO $con = null)
    1160:     {
    1161:         if ($con === null) {
    1162:             $con = Propel::getConnection(ProductCategoryPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
    1163:         }
    1164:
    1165:         if ($values instanceof Criteria) {
    1166:             $criteria = clone $values; // rename for clarity
    1167:         } else {
    1168:             $criteria = $values->buildCriteria(); // build Criteria from ProductCategory object
    1169:         }
    1170:
    1171:
    1172:         // Set the correct dbName
    1173:         $criteria->setDbName(ProductCategoryPeer::DATABASE_NAME);
    1174:
    1175:         try {
    1176:             // use transaction because $criteria could contain info
    1177:             // for more than one table (I guess, conceivably)
    1178:             $con->beginTransaction();
    1179:             $pk = BasePeer::doInsert($criteria, $con);
    1180:             $con->commit();
    1181:         } catch (PropelException $e) {
    1182:             $con->rollBack();
    1183:             throw $e;
    1184:         }
    1185:
    1186:         return $pk;
    1187:     }
    1188:
    1189:     /**
    1190:      * Performs an UPDATE on the database, given a ProductCategory or Criteria object.
    1191:      *
    1192:      * @param      mixed $values Criteria or ProductCategory object containing data that is used to create the UPDATE statement.
    1193:      * @param      PropelPDO $con The connection to use (specify PropelPDO connection object to exert more control over transactions).
    1194:      * @return int             The number of affected rows (if supported by underlying database driver).
    1195:      * @throws PropelException Any exceptions caught during processing will be
    1196:      *       rethrown wrapped into a PropelException.
    1197:      */
    1198:     public static function doUpdate($values, PropelPDO $con = null)
    1199:     {
    1200:         if ($con === null) {
    1201:             $con = Propel::getConnection(ProductCategoryPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
    1202:         }
    1203:
    1204:         $selectCriteria = new Criteria(ProductCategoryPeer::DATABASE_NAME);
    1205:
    1206:         if ($values instanceof Criteria) {
    1207:             $criteria = clone $values; // rename for clarity
    1208:
    1209:             $comparison = $criteria->getComparison(ProductCategoryPeer::PRODUCT_ID);
    1210:             $value = $criteria->remove(ProductCategoryPeer::PRODUCT_ID);
    1211:             if ($value) {
    1212:                 $selectCriteria->add(ProductCategoryPeer::PRODUCT_ID, $value, $comparison);
    1213:             } else {
    1214:                 $selectCriteria->setPrimaryTableName(ProductCategoryPeer::TABLE_NAME);
    1215:             }
    1216:
    1217:             $comparison = $criteria->getComparison(ProductCategoryPeer::CATEGORY_ID);
    1218:             $value = $criteria->remove(ProductCategoryPeer::CATEGORY_ID);
    1219:             if ($value) {
    1220:                 $selectCriteria->add(ProductCategoryPeer::CATEGORY_ID, $value, $comparison);
    1221:             } else {
    1222:                 $selectCriteria->setPrimaryTableName(ProductCategoryPeer::TABLE_NAME);
    1223:             }
    1224:
    1225:         } else { // $values is ProductCategory object
    1226:             $criteria = $values->buildCriteria(); // gets full criteria
    1227:             $selectCriteria = $values->buildPkeyCriteria(); // gets criteria w/ primary key(s)
    1228:         }
    1229:
    1230:         // set the correct dbName
    1231:         $criteria->setDbName(ProductCategoryPeer::DATABASE_NAME);
    1232:
    1233:         return BasePeer::doUpdate($selectCriteria, $criteria, $con);
    1234:     }
    1235:
    1236:     /**
    1237:      * Deletes all rows from the product_category table.
    1238:      *
    1239:      * @param      PropelPDO $con the connection to use
    1240:      * @return int             The number of affected rows (if supported by underlying database driver).
    1241:      * @throws PropelException
    1242:      */
    1243:     public static function doDeleteAll(PropelPDO $con = null)
    1244:     {
    1245:         if ($con === null) {
    1246:             $con = Propel::getConnection(ProductCategoryPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
    1247:         }
    1248:         $affectedRows = 0; // initialize var to track total num of affected rows
    1249:         try {
    1250:             // use transaction because $criteria could contain info
    1251:             // for more than one table or we could emulating ON DELETE CASCADE, etc.
    1252:             $con->beginTransaction();
    1253:             $affectedRows += BasePeer::doDeleteAll(ProductCategoryPeer::TABLE_NAME, $con, ProductCategoryPeer::DATABASE_NAME);
    1254:             // Because this db requires some delete cascade/set null emulation, we have to
    1255:             // clear the cached instance *after* the emulation has happened (since
    1256:             // instances get re-added by the select statement contained therein).
    1257:             ProductCategoryPeer::clearInstancePool();
    1258:             ProductCategoryPeer::clearRelatedInstancePool();
    1259:             $con->commit();
    1260:
    1261:             return $affectedRows;
    1262:         } catch (PropelException $e) {
    1263:             $con->rollBack();
    1264:             throw $e;
    1265:         }
    1266:     }
    1267:
    1268:     /**
    1269:      * Performs a DELETE on the database, given a ProductCategory or Criteria object OR a primary key value.
    1270:      *
    1271:      * @param      mixed $values Criteria or ProductCategory object or primary key or array of primary keys
    1272:      *              which is used to create the DELETE statement
    1273:      * @param      PropelPDO $con the connection to use
    1274:      * @return int The number of affected rows (if supported by underlying database driver).  This includes CASCADE-related rows
    1275:      *              if supported by native driver or if emulated using Propel.
    1276:      * @throws PropelException Any exceptions caught during processing will be
    1277:      *       rethrown wrapped into a PropelException.
    1278:      */
    1279:      public static function doDelete($values, PropelPDO $con = null)
    1280:      {
    1281:         if ($con === null) {
    1282:             $con = Propel::getConnection(ProductCategoryPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
    1283:         }
    1284:
    1285:         if ($values instanceof Criteria) {
    1286:             // invalidate the cache for all objects of this type, since we have no
    1287:             // way of knowing (without running a query) what objects should be invalidated
    1288:             // from the cache based on this Criteria.
    1289:             ProductCategoryPeer::clearInstancePool();
    1290:             // rename for clarity
    1291:             $criteria = clone $values;
    1292:         } elseif ($values instanceof ProductCategory) { // it's a model object
    1293:             // invalidate the cache for this single object
    1294:             ProductCategoryPeer::removeInstanceFromPool($values);
    1295:             // create criteria based on pk values
    1296:             $criteria = $values->buildPkeyCriteria();
    1297:         } else { // it's a primary key, or an array of pks
    1298:             $criteria = new Criteria(ProductCategoryPeer::DATABASE_NAME);
    1299:             // primary key is composite; we therefore, expect
    1300:             // the primary key passed to be an array of pkey values
    1301:             if (count($values) == count($values, COUNT_RECURSIVE)) {
    1302:                 // array is not multi-dimensional
    1303:                 $values = array($values);
    1304:             }
    1305:             foreach ($values as $value) {
    1306:                 $criterion = $criteria->getNewCriterion(ProductCategoryPeer::PRODUCT_ID, $value[0]);
    1307:                 $criterion->addAnd($criteria->getNewCriterion(ProductCategoryPeer::CATEGORY_ID, $value[1]));
    1308:                 $criteria->addOr($criterion);
    1309:                 // we can invalidate the cache for this single PK
    1310:                 ProductCategoryPeer::removeInstanceFromPool($value);
    1311:             }
    1312:         }
    1313:
    1314:         // Set the correct dbName
    1315:         $criteria->setDbName(ProductCategoryPeer::DATABASE_NAME);
    1316:
    1317:         $affectedRows = 0; // initialize var to track total num of affected rows
    1318:
    1319:         try {
    1320:             // use transaction because $criteria could contain info
    1321:             // for more than one table or we could emulating ON DELETE CASCADE, etc.
    1322:             $con->beginTransaction();
    1323:
    1324:             $affectedRows += BasePeer::doDelete($criteria, $con);
    1325:             ProductCategoryPeer::clearRelatedInstancePool();
    1326:             $con->commit();
    1327:
    1328:             return $affectedRows;
    1329:         } catch (PropelException $e) {
    1330:             $con->rollBack();
    1331:             throw $e;
    1332:         }
    1333:     }
    1334:
    1335:     /**
    1336:      * Validates all modified columns of given ProductCategory object.
    1337:      * If parameter $columns is either a single column name or an array of column names
    1338:      * than only those columns are validated.
    1339:      *
    1340:      * NOTICE: This does not apply to primary or foreign keys for now.
    1341:      *
    1342:      * @param      ProductCategory $obj The object to validate.
    1343:      * @param      mixed $cols Column name or array of column names.
    1344:      *
    1345:      * @return mixed TRUE if all columns are valid or the error message of the first invalid column.
    1346:      */
    1347:     public static function doValidate($obj, $cols = null)
    1348:     {
    1349:         $columns = array();
    1350:
    1351:         if ($cols) {
    1352:             $dbMap = Propel::getDatabaseMap(ProductCategoryPeer::DATABASE_NAME);
    1353:             $tableMap = $dbMap->getTable(ProductCategoryPeer::TABLE_NAME);
    1354:
    1355:             if (! is_array($cols)) {
    1356:                 $cols = array($cols);
    1357:             }
    1358:
    1359:             foreach ($cols as $colName) {
    1360:                 if ($tableMap->hasColumn($colName)) {
    1361:                     $get = 'get' . $tableMap->getColumn($colName)->getPhpName();
    1362:                     $columns[$colName] = $obj->$get();
    1363:                 }
    1364:             }
    1365:         } else {
    1366:
    1367:         }
    1368:
    1369:         return BasePeer::doValidate(ProductCategoryPeer::DATABASE_NAME, ProductCategoryPeer::TABLE_NAME, $columns);
    1370:     }
    1371:
    1372:     /**
    1373:      * Retrieve object using using composite pkey values.
    1374:      * @param   int $product_id
    1375:      * @param   int $category_id
    1376:      * @param      PropelPDO $con
    1377:      * @return   ProductCategory
    1378:      */
    1379:     public static function retrieveByPK($product_id, $category_id, PropelPDO $con = null) {
    1380:         $_instancePoolKey = serialize(array((string) $product_id, (string) $category_id));
    1381:          if (null !== ($obj = ProductCategoryPeer::getInstanceFromPool($_instancePoolKey))) {
    1382:              return $obj;
    1383:         }
    1384:
    1385:         if ($con === null) {
    1386:             $con = Propel::getConnection(ProductCategoryPeer::DATABASE_NAME, Propel::CONNECTION_READ);
    1387:         }
    1388:         $criteria = new Criteria(ProductCategoryPeer::DATABASE_NAME);
    1389:         $criteria->add(ProductCategoryPeer::PRODUCT_ID, $product_id);
    1390:         $criteria->add(ProductCategoryPeer::CATEGORY_ID, $category_id);
    1391:         $v = ProductCategoryPeer::doSelect($criteria, $con);
    1392:
    1393:         return !empty($v) ? $v[0] : null;
    1394:     }
    1395: } // BaseProductCategoryPeer
    1396:
    1397: // This is the static code needed to register the TableMap for this table with the main Propel class.
    1398: //
    1399: BaseProductCategoryPeer::buildTableMap();
    1400:
    1401: