# File core/lib/Thelia/Model/om/BaseProductCategoryPeer.php | thelia

       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 durirectly (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()
     372:     {
     373:         ProductCategoryPeer::$instances = array();
     374:     }
     375:
     376:     /**
     377:      * Method to invalidate the instance pool of all tables related to product_category
     378:      * by a foreign key with ON DELETE CASCADE
     379:      */
     380:     public static function clearRelatedInstancePool()
     381:     {
     382:     }
     383:
     384:     /**
     385:      * 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.
     386:      *
     387:      * For tables with a single-column primary key, that simple pkey value will be returned.  For tables with
     388:      * a multi-column primary key, a serialize()d version of the primary key will be returned.
     389:      *
     390:      * @param      array $row PropelPDO resultset row.
     391:      * @param      int $startcol The 0-based offset for reading from the resultset row.
     392:      * @return string A string version of PK or null if the components of primary key in result array are all null.
     393:      */
     394:     public static function getPrimaryKeyHashFromRow($row, $startcol = 0)
     395:     {
     396:         // If the PK cannot be derived from the row, return null.
     397:         if ($row[$startcol] === null && $row[$startcol + 1] === null) {
     398:             return null;
     399:         }
     400:
     401:         return serialize(array((string) $row[$startcol], (string) $row[$startcol + 1]));
     402:     }
     403:
     404:     /**
     405:      * Retrieves the primary key from the DB resultset row
     406:      * For tables with a single-column primary key, that simple pkey value will be returned.  For tables with
     407:      * a multi-column primary key, an array of the primary key columns will be returned.
     408:      *
     409:      * @param      array $row PropelPDO resultset row.
     410:      * @param      int $startcol The 0-based offset for reading from the resultset row.
     411:      * @return mixed The primary key of the row
     412:      */
     413:     public static function getPrimaryKeyFromRow($row, $startcol = 0)
     414:     {
     415:
     416:         return array((int) $row[$startcol], (int) $row[$startcol + 1]);
     417:     }
     418:
     419:     /**
     420:      * The returned array will contain objects of the default type or
     421:      * objects that inherit from the default.
     422:      *
     423:      * @throws PropelException Any exceptions caught during processing will be
     424:      *       rethrown wrapped into a PropelException.
     425:      */
     426:     public static function populateObjects(PDOStatement $stmt)
     427:     {
     428:         $results = array();
     429:
     430:         // set the class once to avoid overhead in the loop
     431:         $cls = ProductCategoryPeer::getOMClass();
     432:         // populate the object(s)
     433:         while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     434:             $key = ProductCategoryPeer::getPrimaryKeyHashFromRow($row, 0);
     435:             if (null !== ($obj = ProductCategoryPeer::getInstanceFromPool($key))) {
     436:                 // We no longer rehydrate the object, since this can cause data loss.
     437:                 // See http://www.propelorm.org/ticket/509
     438:                 // $obj->hydrate($row, 0, true); // rehydrate
     439:                 $results[] = $obj;
     440:             } else {
     441:                 $obj = new $cls();
     442:                 $obj->hydrate($row);
     443:                 $results[] = $obj;
     444:                 ProductCategoryPeer::addInstanceToPool($obj, $key);
     445:             } // if key exists
     446:         }
     447:         $stmt->closeCursor();
     448:
     449:         return $results;
     450:     }
     451:     /**
     452:      * Populates an object of the default type or an object that inherit from the default.
     453:      *
     454:      * @param      array $row PropelPDO resultset row.
     455:      * @param      int $startcol The 0-based offset for reading from the resultset row.
     456:      * @throws PropelException Any exceptions caught during processing will be
     457:      *       rethrown wrapped into a PropelException.
     458:      * @return array (ProductCategory object, last column rank)
     459:      */
     460:     public static function populateObject($row, $startcol = 0)
     461:     {
     462:         $key = ProductCategoryPeer::getPrimaryKeyHashFromRow($row, $startcol);
     463:         if (null !== ($obj = ProductCategoryPeer::getInstanceFromPool($key))) {
     464:             // We no longer rehydrate the object, since this can cause data loss.
     465:             // See http://www.propelorm.org/ticket/509
     466:             // $obj->hydrate($row, $startcol, true); // rehydrate
     467:             $col = $startcol + ProductCategoryPeer::NUM_HYDRATE_COLUMNS;
     468:         } else {
     469:             $cls = ProductCategoryPeer::OM_CLASS;
     470:             $obj = new $cls();
     471:             $col = $obj->hydrate($row, $startcol);
     472:             ProductCategoryPeer::addInstanceToPool($obj, $key);
     473:         }
     474:
     475:         return array($obj, $col);
     476:     }
     477:
     478:
     479:     /**
     480:      * Returns the number of rows matching criteria, joining the related Product table
     481:      *
     482:      * @param      Criteria $criteria
     483:      * @param      boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
     484:      * @param      PropelPDO $con
     485:      * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
     486:      * @return int Number of matching rows.
     487:      */
     488:     public static function doCountJoinProduct(Criteria $criteria, $distinct = false, PropelPDO $con = null, $join_behavior = Criteria::LEFT_JOIN)
     489:     {
     490:         // we're going to modify criteria, so copy it first
     491:         $criteria = clone $criteria;
     492:
     493:         // We need to set the primary table name, since in the case that there are no WHERE columns
     494:         // it will be impossible for the BasePeer::createSelectSql() method to determine which
     495:         // tables go into the FROM clause.
     496:         $criteria->setPrimaryTableName(ProductCategoryPeer::TABLE_NAME);
     497:
     498:         if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
     499:             $criteria->setDistinct();
     500:         }
     501:
     502:         if (!$criteria->hasSelectClause()) {
     503:             ProductCategoryPeer::addSelectColumns($criteria);
     504:         }
     505:
     506:         $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
     507:
     508:         // Set the correct dbName
     509:         $criteria->setDbName(ProductCategoryPeer::DATABASE_NAME);
     510:
     511:         if ($con === null) {
     512:             $con = Propel::getConnection(ProductCategoryPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     513:         }
     514:
     515:         $criteria->addJoin(ProductCategoryPeer::PRODUCT_ID, ProductPeer::ID, $join_behavior);
     516:
     517:         $stmt = BasePeer::doCount($criteria, $con);
     518:
     519:         if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     520:             $count = (int) $row[0];
     521:         } else {
     522:             $count = 0; // no rows returned; we infer that means 0 matches.
     523:         }
     524:         $stmt->closeCursor();
     525:
     526:         return $count;
     527:     }
     528:
     529:
     530:     /**
     531:      * Returns the number of rows matching criteria, joining the related Category table
     532:      *
     533:      * @param      Criteria $criteria
     534:      * @param      boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
     535:      * @param      PropelPDO $con
     536:      * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
     537:      * @return int Number of matching rows.
     538:      */
     539:     public static function doCountJoinCategory(Criteria $criteria, $distinct = false, PropelPDO $con = null, $join_behavior = Criteria::LEFT_JOIN)
     540:     {
     541:         // we're going to modify criteria, so copy it first
     542:         $criteria = clone $criteria;
     543:
     544:         // We need to set the primary table name, since in the case that there are no WHERE columns
     545:         // it will be impossible for the BasePeer::createSelectSql() method to determine which
     546:         // tables go into the FROM clause.
     547:         $criteria->setPrimaryTableName(ProductCategoryPeer::TABLE_NAME);
     548:
     549:         if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
     550:             $criteria->setDistinct();
     551:         }
     552:
     553:         if (!$criteria->hasSelectClause()) {
     554:             ProductCategoryPeer::addSelectColumns($criteria);
     555:         }
     556:
     557:         $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
     558:
     559:         // Set the correct dbName
     560:         $criteria->setDbName(ProductCategoryPeer::DATABASE_NAME);
     561:
     562:         if ($con === null) {
     563:             $con = Propel::getConnection(ProductCategoryPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     564:         }
     565:
     566:         $criteria->addJoin(ProductCategoryPeer::CATEGORY_ID, CategoryPeer::ID, $join_behavior);
     567:
     568:         $stmt = BasePeer::doCount($criteria, $con);
     569:
     570:         if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     571:             $count = (int) $row[0];
     572:         } else {
     573:             $count = 0; // no rows returned; we infer that means 0 matches.
     574:         }
     575:         $stmt->closeCursor();
     576:
     577:         return $count;
     578:     }
     579:
     580:
     581:     /**
     582:      * Selects a collection of ProductCategory objects pre-filled with their Product objects.
     583:      * @param      Criteria  $criteria
     584:      * @param      PropelPDO $con
     585:      * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
     586:      * @return array           Array of ProductCategory objects.
     587:      * @throws PropelException Any exceptions caught during processing will be
     588:      *       rethrown wrapped into a PropelException.
     589:      */
     590:     public static function doSelectJoinProduct(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
     591:     {
     592:         $criteria = clone $criteria;
     593:
     594:         // Set the correct dbName if it has not been overridden
     595:         if ($criteria->getDbName() == Propel::getDefaultDB()) {
     596:             $criteria->setDbName(ProductCategoryPeer::DATABASE_NAME);
     597:         }
     598:
     599:         ProductCategoryPeer::addSelectColumns($criteria);
     600:         $startcol = ProductCategoryPeer::NUM_HYDRATE_COLUMNS;
     601:         ProductPeer::addSelectColumns($criteria);
     602:
     603:         $criteria->addJoin(ProductCategoryPeer::PRODUCT_ID, ProductPeer::ID, $join_behavior);
     604:
     605:         $stmt = BasePeer::doSelect($criteria, $con);
     606:         $results = array();
     607:
     608:         while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     609:             $key1 = ProductCategoryPeer::getPrimaryKeyHashFromRow($row, 0);
     610:             if (null !== ($obj1 = ProductCategoryPeer::getInstanceFromPool($key1))) {
     611:                 // We no longer rehydrate the object, since this can cause data loss.
     612:                 // See http://www.propelorm.org/ticket/509
     613:                 // $obj1->hydrate($row, 0, true); // rehydrate
     614:             } else {
     615:
     616:                 $cls = ProductCategoryPeer::getOMClass();
     617:
     618:                 $obj1 = new $cls();
     619:                 $obj1->hydrate($row);
     620:                 ProductCategoryPeer::addInstanceToPool($obj1, $key1);
     621:             } // if $obj1 already loaded
     622:
     623:             $key2 = ProductPeer::getPrimaryKeyHashFromRow($row, $startcol);
     624:             if ($key2 !== null) {
     625:                 $obj2 = ProductPeer::getInstanceFromPool($key2);
     626:                 if (!$obj2) {
     627:
     628:                     $cls = ProductPeer::getOMClass();
     629:
     630:                     $obj2 = new $cls();
     631:                     $obj2->hydrate($row, $startcol);
     632:                     ProductPeer::addInstanceToPool($obj2, $key2);
     633:                 } // if obj2 already loaded
     634:
     635:                 // Add the $obj1 (ProductCategory) to $obj2 (Product)
     636:                 $obj2->addProductCategory($obj1);
     637:
     638:             } // if joined row was not null
     639:
     640:             $results[] = $obj1;
     641:         }
     642:         $stmt->closeCursor();
     643:
     644:         return $results;
     645:     }
     646:
     647:
     648:     /**
     649:      * Selects a collection of ProductCategory objects pre-filled with their Category objects.
     650:      * @param      Criteria  $criteria
     651:      * @param      PropelPDO $con
     652:      * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
     653:      * @return array           Array of ProductCategory objects.
     654:      * @throws PropelException Any exceptions caught during processing will be
     655:      *       rethrown wrapped into a PropelException.
     656:      */
     657:     public static function doSelectJoinCategory(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
     658:     {
     659:         $criteria = clone $criteria;
     660:
     661:         // Set the correct dbName if it has not been overridden
     662:         if ($criteria->getDbName() == Propel::getDefaultDB()) {
     663:             $criteria->setDbName(ProductCategoryPeer::DATABASE_NAME);
     664:         }
     665:
     666:         ProductCategoryPeer::addSelectColumns($criteria);
     667:         $startcol = ProductCategoryPeer::NUM_HYDRATE_COLUMNS;
     668:         CategoryPeer::addSelectColumns($criteria);
     669:
     670:         $criteria->addJoin(ProductCategoryPeer::CATEGORY_ID, CategoryPeer::ID, $join_behavior);
     671:
     672:         $stmt = BasePeer::doSelect($criteria, $con);
     673:         $results = array();
     674:
     675:         while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     676:             $key1 = ProductCategoryPeer::getPrimaryKeyHashFromRow($row, 0);
     677:             if (null !== ($obj1 = ProductCategoryPeer::getInstanceFromPool($key1))) {
     678:                 // We no longer rehydrate the object, since this can cause data loss.
     679:                 // See http://www.propelorm.org/ticket/509
     680:                 // $obj1->hydrate($row, 0, true); // rehydrate
     681:             } else {
     682:
     683:                 $cls = ProductCategoryPeer::getOMClass();
     684:
     685:                 $obj1 = new $cls();
     686:                 $obj1->hydrate($row);
     687:                 ProductCategoryPeer::addInstanceToPool($obj1, $key1);
     688:             } // if $obj1 already loaded
     689:
     690:             $key2 = CategoryPeer::getPrimaryKeyHashFromRow($row, $startcol);
     691:             if ($key2 !== null) {
     692:                 $obj2 = CategoryPeer::getInstanceFromPool($key2);
     693:                 if (!$obj2) {
     694:
     695:                     $cls = CategoryPeer::getOMClass();
     696:
     697:                     $obj2 = new $cls();
     698:                     $obj2->hydrate($row, $startcol);
     699:                     CategoryPeer::addInstanceToPool($obj2, $key2);
     700:                 } // if obj2 already loaded
     701:
     702:                 // Add the $obj1 (ProductCategory) to $obj2 (Category)
     703:                 $obj2->addProductCategory($obj1);
     704:
     705:             } // if joined row was not null
     706:
     707:             $results[] = $obj1;
     708:         }
     709:         $stmt->closeCursor();
     710:
     711:         return $results;
     712:     }
     713:
     714:
     715:     /**
     716:      * Returns the number of rows matching criteria, joining all related tables
     717:      *
     718:      * @param      Criteria $criteria
     719:      * @param      boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
     720:      * @param      PropelPDO $con
     721:      * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
     722:      * @return int Number of matching rows.
     723:      */
     724:     public static function doCountJoinAll(Criteria $criteria, $distinct = false, PropelPDO $con = null, $join_behavior = Criteria::LEFT_JOIN)
     725:     {
     726:         // we're going to modify criteria, so copy it first
     727:         $criteria = clone $criteria;
     728:
     729:         // We need to set the primary table name, since in the case that there are no WHERE columns
     730:         // it will be impossible for the BasePeer::createSelectSql() method to determine which
     731:         // tables go into the FROM clause.
     732:         $criteria->setPrimaryTableName(ProductCategoryPeer::TABLE_NAME);
     733:
     734:         if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
     735:             $criteria->setDistinct();
     736:         }
     737:
     738:         if (!$criteria->hasSelectClause()) {
     739:             ProductCategoryPeer::addSelectColumns($criteria);
     740:         }
     741:
     742:         $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
     743:
     744:         // Set the correct dbName
     745:         $criteria->setDbName(ProductCategoryPeer::DATABASE_NAME);
     746:
     747:         if ($con === null) {
     748:             $con = Propel::getConnection(ProductCategoryPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     749:         }
     750:
     751:         $criteria->addJoin(ProductCategoryPeer::PRODUCT_ID, ProductPeer::ID, $join_behavior);
     752:
     753:         $criteria->addJoin(ProductCategoryPeer::CATEGORY_ID, CategoryPeer::ID, $join_behavior);
     754:
     755:         $stmt = BasePeer::doCount($criteria, $con);
     756:
     757:         if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     758:             $count = (int) $row[0];
     759:         } else {
     760:             $count = 0; // no rows returned; we infer that means 0 matches.
     761:         }
     762:         $stmt->closeCursor();
     763:
     764:         return $count;
     765:     }
     766:
     767:     /**
     768:      * Selects a collection of ProductCategory objects pre-filled with all related objects.
     769:      *
     770:      * @param      Criteria  $criteria
     771:      * @param      PropelPDO $con
     772:      * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
     773:      * @return array           Array of ProductCategory objects.
     774:      * @throws PropelException Any exceptions caught during processing will be
     775:      *       rethrown wrapped into a PropelException.
     776:      */
     777:     public static function doSelectJoinAll(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
     778:     {
     779:         $criteria = clone $criteria;
     780:
     781:         // Set the correct dbName if it has not been overridden
     782:         if ($criteria->getDbName() == Propel::getDefaultDB()) {
     783:             $criteria->setDbName(ProductCategoryPeer::DATABASE_NAME);
     784:         }
     785:
     786:         ProductCategoryPeer::addSelectColumns($criteria);
     787:         $startcol2 = ProductCategoryPeer::NUM_HYDRATE_COLUMNS;
     788:
     789:         ProductPeer::addSelectColumns($criteria);
     790:         $startcol3 = $startcol2 + ProductPeer::NUM_HYDRATE_COLUMNS;
     791:
     792:         CategoryPeer::addSelectColumns($criteria);
     793:         $startcol4 = $startcol3 + CategoryPeer::NUM_HYDRATE_COLUMNS;
     794:
     795:         $criteria->addJoin(ProductCategoryPeer::PRODUCT_ID, ProductPeer::ID, $join_behavior);
     796:
     797:         $criteria->addJoin(ProductCategoryPeer::CATEGORY_ID, CategoryPeer::ID, $join_behavior);
     798:
     799:         $stmt = BasePeer::doSelect($criteria, $con);
     800:         $results = array();
     801:
     802:         while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     803:             $key1 = ProductCategoryPeer::getPrimaryKeyHashFromRow($row, 0);
     804:             if (null !== ($obj1 = ProductCategoryPeer::getInstanceFromPool($key1))) {
     805:                 // We no longer rehydrate the object, since this can cause data loss.
     806:                 // See http://www.propelorm.org/ticket/509
     807:                 // $obj1->hydrate($row, 0, true); // rehydrate
     808:             } else {
     809:                 $cls = ProductCategoryPeer::getOMClass();
     810:
     811:                 $obj1 = new $cls();
     812:                 $obj1->hydrate($row);
     813:                 ProductCategoryPeer::addInstanceToPool($obj1, $key1);
     814:             } // if obj1 already loaded
     815:
     816:             // Add objects for joined Product rows
     817:
     818:             $key2 = ProductPeer::getPrimaryKeyHashFromRow($row, $startcol2);
     819:             if ($key2 !== null) {
     820:                 $obj2 = ProductPeer::getInstanceFromPool($key2);
     821:                 if (!$obj2) {
     822:
     823:                     $cls = ProductPeer::getOMClass();
     824:
     825:                     $obj2 = new $cls();
     826:                     $obj2->hydrate($row, $startcol2);
     827:                     ProductPeer::addInstanceToPool($obj2, $key2);
     828:                 } // if obj2 loaded
     829:
     830:                 // Add the $obj1 (ProductCategory) to the collection in $obj2 (Product)
     831:                 $obj2->addProductCategory($obj1);
     832:             } // if joined row not null
     833:
     834:             // Add objects for joined Category rows
     835:
     836:             $key3 = CategoryPeer::getPrimaryKeyHashFromRow($row, $startcol3);
     837:             if ($key3 !== null) {
     838:                 $obj3 = CategoryPeer::getInstanceFromPool($key3);
     839:                 if (!$obj3) {
     840:
     841:                     $cls = CategoryPeer::getOMClass();
     842:
     843:                     $obj3 = new $cls();
     844:                     $obj3->hydrate($row, $startcol3);
     845:                     CategoryPeer::addInstanceToPool($obj3, $key3);
     846:                 } // if obj3 loaded
     847:
     848:                 // Add the $obj1 (ProductCategory) to the collection in $obj3 (Category)
     849:                 $obj3->addProductCategory($obj1);
     850:             } // if joined row not null
     851:
     852:             $results[] = $obj1;
     853:         }
     854:         $stmt->closeCursor();
     855:
     856:         return $results;
     857:     }
     858:
     859:
     860:     /**
     861:      * Returns the number of rows matching criteria, joining the related Product table
     862:      *
     863:      * @param      Criteria $criteria
     864:      * @param      boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
     865:      * @param      PropelPDO $con
     866:      * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
     867:      * @return int Number of matching rows.
     868:      */
     869:     public static function doCountJoinAllExceptProduct(Criteria $criteria, $distinct = false, PropelPDO $con = null, $join_behavior = Criteria::LEFT_JOIN)
     870:     {
     871:         // we're going to modify criteria, so copy it first
     872:         $criteria = clone $criteria;
     873:
     874:         // We need to set the primary table name, since in the case that there are no WHERE columns
     875:         // it will be impossible for the BasePeer::createSelectSql() method to determine which
     876:         // tables go into the FROM clause.
     877:         $criteria->setPrimaryTableName(ProductCategoryPeer::TABLE_NAME);
     878:
     879:         if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
     880:             $criteria->setDistinct();
     881:         }
     882:
     883:         if (!$criteria->hasSelectClause()) {
     884:             ProductCategoryPeer::addSelectColumns($criteria);
     885:         }
     886:
     887:         $criteria->clearOrderByColumns(); // ORDER BY should not affect count
     888:
     889:         // Set the correct dbName
     890:         $criteria->setDbName(ProductCategoryPeer::DATABASE_NAME);
     891:
     892:         if ($con === null) {
     893:             $con = Propel::getConnection(ProductCategoryPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     894:         }
     895:
     896:         $criteria->addJoin(ProductCategoryPeer::CATEGORY_ID, CategoryPeer::ID, $join_behavior);
     897:
     898:         $stmt = BasePeer::doCount($criteria, $con);
     899:
     900:         if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     901:             $count = (int) $row[0];
     902:         } else {
     903:             $count = 0; // no rows returned; we infer that means 0 matches.
     904:         }
     905:         $stmt->closeCursor();
     906:
     907:         return $count;
     908:     }
     909:
     910:
     911:     /**
     912:      * Returns the number of rows matching criteria, joining the related Category table
     913:      *
     914:      * @param      Criteria $criteria
     915:      * @param      boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
     916:      * @param      PropelPDO $con
     917:      * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
     918:      * @return int Number of matching rows.
     919:      */
     920:     public static function doCountJoinAllExceptCategory(Criteria $criteria, $distinct = false, PropelPDO $con = null, $join_behavior = Criteria::LEFT_JOIN)
     921:     {
     922:         // we're going to modify criteria, so copy it first
     923:         $criteria = clone $criteria;
     924:
     925:         // We need to set the primary table name, since in the case that there are no WHERE columns
     926:         // it will be impossible for the BasePeer::createSelectSql() method to determine which
     927:         // tables go into the FROM clause.
     928:         $criteria->setPrimaryTableName(ProductCategoryPeer::TABLE_NAME);
     929:
     930:         if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
     931:             $criteria->setDistinct();
     932:         }
     933:
     934:         if (!$criteria->hasSelectClause()) {
     935:             ProductCategoryPeer::addSelectColumns($criteria);
     936:         }
     937:
     938:         $criteria->clearOrderByColumns(); // ORDER BY should not affect count
     939:
     940:         // Set the correct dbName
     941:         $criteria->setDbName(ProductCategoryPeer::DATABASE_NAME);
     942:
     943:         if ($con === null) {
     944:             $con = Propel::getConnection(ProductCategoryPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     945:         }
     946:
     947:         $criteria->addJoin(ProductCategoryPeer::PRODUCT_ID, ProductPeer::ID, $join_behavior);
     948:
     949:         $stmt = BasePeer::doCount($criteria, $con);
     950:
     951:         if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     952:             $count = (int) $row[0];
     953:         } else {
     954:             $count = 0; // no rows returned; we infer that means 0 matches.
     955:         }
     956:         $stmt->closeCursor();
     957:
     958:         return $count;
     959:     }
     960:
     961:
     962:     /**
     963:      * Selects a collection of ProductCategory objects pre-filled with all related objects except Product.
     964:      *
     965:      * @param      Criteria  $criteria
     966:      * @param      PropelPDO $con
     967:      * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
     968:      * @return array           Array of ProductCategory objects.
     969:      * @throws PropelException Any exceptions caught during processing will be
     970:      *       rethrown wrapped into a PropelException.
     971:      */
     972:     public static function doSelectJoinAllExceptProduct(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
     973:     {
     974:         $criteria = clone $criteria;
     975:
     976:         // Set the correct dbName if it has not been overridden
     977:         // $criteria->getDbName() will return the same object if not set to another value
     978:         // so == check is okay and faster
     979:         if ($criteria->getDbName() == Propel::getDefaultDB()) {
     980:             $criteria->setDbName(ProductCategoryPeer::DATABASE_NAME);
     981:         }
     982:
     983:         ProductCategoryPeer::addSelectColumns($criteria);
     984:         $startcol2 = ProductCategoryPeer::NUM_HYDRATE_COLUMNS;
     985:
     986:         CategoryPeer::addSelectColumns($criteria);
     987:         $startcol3 = $startcol2 + CategoryPeer::NUM_HYDRATE_COLUMNS;
     988:
     989:         $criteria->addJoin(ProductCategoryPeer::CATEGORY_ID, CategoryPeer::ID, $join_behavior);
     990:
     991:
     992:         $stmt = BasePeer::doSelect($criteria, $con);
     993:         $results = array();
     994:
     995:         while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     996:             $key1 = ProductCategoryPeer::getPrimaryKeyHashFromRow($row, 0);
     997:             if (null !== ($obj1 = ProductCategoryPeer::getInstanceFromPool($key1))) {
     998:                 // We no longer rehydrate the object, since this can cause data loss.
     999:                 // See http://www.propelorm.org/ticket/509
    1000:                 // $obj1->hydrate($row, 0, true); // rehydrate
    1001:             } else {
    1002:                 $cls = ProductCategoryPeer::getOMClass();
    1003:
    1004:                 $obj1 = new $cls();
    1005:                 $obj1->hydrate($row);
    1006:                 ProductCategoryPeer::addInstanceToPool($obj1, $key1);
    1007:             } // if obj1 already loaded
    1008:
    1009:                 // Add objects for joined Category rows
    1010:
    1011:                 $key2 = CategoryPeer::getPrimaryKeyHashFromRow($row, $startcol2);
    1012:                 if ($key2 !== null) {
    1013:                     $obj2 = CategoryPeer::getInstanceFromPool($key2);
    1014:                     if (!$obj2) {
    1015:
    1016:                         $cls = CategoryPeer::getOMClass();
    1017:
    1018:                     $obj2 = new $cls();
    1019:                     $obj2->hydrate($row, $startcol2);
    1020:                     CategoryPeer::addInstanceToPool($obj2, $key2);
    1021:                 } // if $obj2 already loaded
    1022:
    1023:                 // Add the $obj1 (ProductCategory) to the collection in $obj2 (Category)
    1024:                 $obj2->addProductCategory($obj1);
    1025:
    1026:             } // if joined row is not null
    1027:
    1028:             $results[] = $obj1;
    1029:         }
    1030:         $stmt->closeCursor();
    1031:
    1032:         return $results;
    1033:     }
    1034:
    1035:
    1036:     /**
    1037:      * Selects a collection of ProductCategory objects pre-filled with all related objects except Category.
    1038:      *
    1039:      * @param      Criteria  $criteria
    1040:      * @param      PropelPDO $con
    1041:      * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
    1042:      * @return array           Array of ProductCategory objects.
    1043:      * @throws PropelException Any exceptions caught during processing will be
    1044:      *       rethrown wrapped into a PropelException.
    1045:      */
    1046:     public static function doSelectJoinAllExceptCategory(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
    1047:     {
    1048:         $criteria = clone $criteria;
    1049:
    1050:         // Set the correct dbName if it has not been overridden
    1051:         // $criteria->getDbName() will return the same object if not set to another value
    1052:         // so == check is okay and faster
    1053:         if ($criteria->getDbName() == Propel::getDefaultDB()) {
    1054:             $criteria->setDbName(ProductCategoryPeer::DATABASE_NAME);
    1055:         }
    1056:
    1057:         ProductCategoryPeer::addSelectColumns($criteria);
    1058:         $startcol2 = ProductCategoryPeer::NUM_HYDRATE_COLUMNS;
    1059:
    1060:         ProductPeer::addSelectColumns($criteria);
    1061:         $startcol3 = $startcol2 + ProductPeer::NUM_HYDRATE_COLUMNS;
    1062:
    1063:         $criteria->addJoin(ProductCategoryPeer::PRODUCT_ID, ProductPeer::ID, $join_behavior);
    1064:
    1065:
    1066:         $stmt = BasePeer::doSelect($criteria, $con);
    1067:         $results = array();
    1068:
    1069:         while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
    1070:             $key1 = ProductCategoryPeer::getPrimaryKeyHashFromRow($row, 0);
    1071:             if (null !== ($obj1 = ProductCategoryPeer::getInstanceFromPool($key1))) {
    1072:                 // We no longer rehydrate the object, since this can cause data loss.
    1073:                 // See http://www.propelorm.org/ticket/509
    1074:                 // $obj1->hydrate($row, 0, true); // rehydrate
    1075:             } else {
    1076:                 $cls = ProductCategoryPeer::getOMClass();
    1077:
    1078:                 $obj1 = new $cls();
    1079:                 $obj1->hydrate($row);
    1080:                 ProductCategoryPeer::addInstanceToPool($obj1, $key1);
    1081:             } // if obj1 already loaded
    1082:
    1083:                 // Add objects for joined Product rows
    1084:
    1085:                 $key2 = ProductPeer::getPrimaryKeyHashFromRow($row, $startcol2);
    1086:                 if ($key2 !== null) {
    1087:                     $obj2 = ProductPeer::getInstanceFromPool($key2);
    1088:                     if (!$obj2) {
    1089:
    1090:                         $cls = ProductPeer::getOMClass();
    1091:
    1092:                     $obj2 = new $cls();
    1093:                     $obj2->hydrate($row, $startcol2);
    1094:                     ProductPeer::addInstanceToPool($obj2, $key2);
    1095:                 } // if $obj2 already loaded
    1096:
    1097:                 // Add the $obj1 (ProductCategory) to the collection in $obj2 (Product)
    1098:                 $obj2->addProductCategory($obj1);
    1099:
    1100:             } // if joined row is not null
    1101:
    1102:             $results[] = $obj1;
    1103:         }
    1104:         $stmt->closeCursor();
    1105:
    1106:         return $results;
    1107:     }
    1108:
    1109:     /**
    1110:      * Returns the TableMap related to this peer.
    1111:      * This method is not needed for general use but a specific application could have a need.
    1112:      * @return TableMap
    1113:      * @throws PropelException Any exceptions caught during processing will be
    1114:      *       rethrown wrapped into a PropelException.
    1115:      */
    1116:     public static function getTableMap()
    1117:     {
    1118:         return Propel::getDatabaseMap(ProductCategoryPeer::DATABASE_NAME)->getTable(ProductCategoryPeer::TABLE_NAME);
    1119:     }
    1120:
    1121:     /**
    1122:      * Add a TableMap instance to the database for this peer class.
    1123:      */
    1124:     public static function buildTableMap()
    1125:     {
    1126:       $dbMap = Propel::getDatabaseMap(BaseProductCategoryPeer::DATABASE_NAME);
    1127:       if (!$dbMap->hasTable(BaseProductCategoryPeer::TABLE_NAME)) {
    1128:         $dbMap->addTableObject(new ProductCategoryTableMap());
    1129:       }
    1130:     }
    1131:
    1132:     /**
    1133:      * The class that the Peer will make instances of.
    1134:      *
    1135:      *
    1136:      * @return string ClassName
    1137:      */
    1138:     public static function getOMClass()
    1139:     {
    1140:         return ProductCategoryPeer::OM_CLASS;
    1141:     }
    1142:
    1143:     /**
    1144:      * Performs an INSERT on the database, given a ProductCategory or Criteria object.
    1145:      *
    1146:      * @param      mixed $values Criteria or ProductCategory object containing data that is used to create the INSERT statement.
    1147:      * @param      PropelPDO $con the PropelPDO connection to use
    1148:      * @return mixed           The new primary key.
    1149:      * @throws PropelException Any exceptions caught during processing will be
    1150:      *       rethrown wrapped into a PropelException.
    1151:      */
    1152:     public static function doInsert($values, PropelPDO $con = null)
    1153:     {
    1154:         if ($con === null) {
    1155:             $con = Propel::getConnection(ProductCategoryPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
    1156:         }
    1157:
    1158:         if ($values instanceof Criteria) {
    1159:             $criteria = clone $values; // rename for clarity
    1160:         } else {
    1161:             $criteria = $values->buildCriteria(); // build Criteria from ProductCategory object
    1162:         }
    1163:
    1164:
    1165:         // Set the correct dbName
    1166:         $criteria->setDbName(ProductCategoryPeer::DATABASE_NAME);
    1167:
    1168:         try {
    1169:             // use transaction because $criteria could contain info
    1170:             // for more than one table (I guess, conceivably)
    1171:             $con->beginTransaction();
    1172:             $pk = BasePeer::doInsert($criteria, $con);
    1173:             $con->commit();
    1174:         } catch (PropelException $e) {
    1175:             $con->rollBack();
    1176:             throw $e;
    1177:         }
    1178:
    1179:         return $pk;
    1180:     }
    1181:
    1182:     /**
    1183:      * Performs an UPDATE on the database, given a ProductCategory or Criteria object.
    1184:      *
    1185:      * @param      mixed $values Criteria or ProductCategory object containing data that is used to create the UPDATE statement.
    1186:      * @param      PropelPDO $con The connection to use (specify PropelPDO connection object to exert more control over transactions).
    1187:      * @return int             The number of affected rows (if supported by underlying database driver).
    1188:      * @throws PropelException Any exceptions caught during processing will be
    1189:      *       rethrown wrapped into a PropelException.
    1190:      */
    1191:     public static function doUpdate($values, PropelPDO $con = null)
    1192:     {
    1193:         if ($con === null) {
    1194:             $con = Propel::getConnection(ProductCategoryPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
    1195:         }
    1196:
    1197:         $selectCriteria = new Criteria(ProductCategoryPeer::DATABASE_NAME);
    1198:
    1199:         if ($values instanceof Criteria) {
    1200:             $criteria = clone $values; // rename for clarity
    1201:
    1202:             $comparison = $criteria->getComparison(ProductCategoryPeer::PRODUCT_ID);
    1203:             $value = $criteria->remove(ProductCategoryPeer::PRODUCT_ID);
    1204:             if ($value) {
    1205:                 $selectCriteria->add(ProductCategoryPeer::PRODUCT_ID, $value, $comparison);
    1206:             } else {
    1207:                 $selectCriteria->setPrimaryTableName(ProductCategoryPeer::TABLE_NAME);
    1208:             }
    1209:
    1210:             $comparison = $criteria->getComparison(ProductCategoryPeer::CATEGORY_ID);
    1211:             $value = $criteria->remove(ProductCategoryPeer::CATEGORY_ID);
    1212:             if ($value) {
    1213:                 $selectCriteria->add(ProductCategoryPeer::CATEGORY_ID, $value, $comparison);
    1214:             } else {
    1215:                 $selectCriteria->setPrimaryTableName(ProductCategoryPeer::TABLE_NAME);
    1216:             }
    1217:
    1218:         } else { // $values is ProductCategory object
    1219:             $criteria = $values->buildCriteria(); // gets full criteria
    1220:             $selectCriteria = $values->buildPkeyCriteria(); // gets criteria w/ primary key(s)
    1221:         }
    1222:
    1223:         // set the correct dbName
    1224:         $criteria->setDbName(ProductCategoryPeer::DATABASE_NAME);
    1225:
    1226:         return BasePeer::doUpdate($selectCriteria, $criteria, $con);
    1227:     }
    1228:
    1229:     /**
    1230:      * Deletes all rows from the product_category table.
    1231:      *
    1232:      * @param      PropelPDO $con the connection to use
    1233:      * @return int             The number of affected rows (if supported by underlying database driver).
    1234:      * @throws PropelException
    1235:      */
    1236:     public static function doDeleteAll(PropelPDO $con = null)
    1237:     {
    1238:         if ($con === null) {
    1239:             $con = Propel::getConnection(ProductCategoryPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
    1240:         }
    1241:         $affectedRows = 0; // initialize var to track total num of affected rows
    1242:         try {
    1243:             // use transaction because $criteria could contain info
    1244:             // for more than one table or we could emulating ON DELETE CASCADE, etc.
    1245:             $con->beginTransaction();
    1246:             $affectedRows += BasePeer::doDeleteAll(ProductCategoryPeer::TABLE_NAME, $con, ProductCategoryPeer::DATABASE_NAME);
    1247:             // Because this db requires some delete cascade/set null emulation, we have to
    1248:             // clear the cached instance *after* the emulation has happened (since
    1249:             // instances get re-added by the select statement contained therein).
    1250:             ProductCategoryPeer::clearInstancePool();
    1251:             ProductCategoryPeer::clearRelatedInstancePool();
    1252:             $con->commit();
    1253:
    1254:             return $affectedRows;
    1255:         } catch (PropelException $e) {
    1256:             $con->rollBack();
    1257:             throw $e;
    1258:         }
    1259:     }
    1260:
    1261:     /**
    1262:      * Performs a DELETE on the database, given a ProductCategory or Criteria object OR a primary key value.
    1263:      *
    1264:      * @param      mixed $values Criteria or ProductCategory object or primary key or array of primary keys
    1265:      *              which is used to create the DELETE statement
    1266:      * @param      PropelPDO $con the connection to use
    1267:      * @return int The number of affected rows (if supported by underlying database driver).  This includes CASCADE-related rows
    1268:      *              if supported by native driver or if emulated using Propel.
    1269:      * @throws PropelException Any exceptions caught during processing will be
    1270:      *       rethrown wrapped into a PropelException.
    1271:      */
    1272:      public static function doDelete($values, PropelPDO $con = null)
    1273:      {
    1274:         if ($con === null) {
    1275:             $con = Propel::getConnection(ProductCategoryPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
    1276:         }
    1277:
    1278:         if ($values instanceof Criteria) {
    1279:             // invalidate the cache for all objects of this type, since we have no
    1280:             // way of knowing (without running a query) what objects should be invalidated
    1281:             // from the cache based on this Criteria.
    1282:             ProductCategoryPeer::clearInstancePool();
    1283:             // rename for clarity
    1284:             $criteria = clone $values;
    1285:         } elseif ($values instanceof ProductCategory) { // it's a model object
    1286:             // invalidate the cache for this single object
    1287:             ProductCategoryPeer::removeInstanceFromPool($values);
    1288:             // create criteria based on pk values
    1289:             $criteria = $values->buildPkeyCriteria();
    1290:         } else { // it's a primary key, or an array of pks
    1291:             $criteria = new Criteria(ProductCategoryPeer::DATABASE_NAME);
    1292:             // primary key is composite; we therefore, expect
    1293:             // the primary key passed to be an array of pkey values
    1294:             if (count($values) == count($values, COUNT_RECURSIVE)) {
    1295:                 // array is not multi-dimensional
    1296:                 $values = array($values);
    1297:             }
    1298:             foreach ($values as $value) {
    1299:                 $criterion = $criteria->getNewCriterion(ProductCategoryPeer::PRODUCT_ID, $value[0]);
    1300:                 $criterion->addAnd($criteria->getNewCriterion(ProductCategoryPeer::CATEGORY_ID, $value[1]));
    1301:                 $criteria->addOr($criterion);
    1302:                 // we can invalidate the cache for this single PK
    1303:                 ProductCategoryPeer::removeInstanceFromPool($value);
    1304:             }
    1305:         }
    1306:
    1307:         // Set the correct dbName
    1308:         $criteria->setDbName(ProductCategoryPeer::DATABASE_NAME);
    1309:
    1310:         $affectedRows = 0; // initialize var to track total num of affected rows
    1311:
    1312:         try {
    1313:             // use transaction because $criteria could contain info
    1314:             // for more than one table or we could emulating ON DELETE CASCADE, etc.
    1315:             $con->beginTransaction();
    1316:
    1317:             $affectedRows += BasePeer::doDelete($criteria, $con);
    1318:             ProductCategoryPeer::clearRelatedInstancePool();
    1319:             $con->commit();
    1320:
    1321:             return $affectedRows;
    1322:         } catch (PropelException $e) {
    1323:             $con->rollBack();
    1324:             throw $e;
    1325:         }
    1326:     }
    1327:
    1328:     /**
    1329:      * Validates all modified columns of given ProductCategory object.
    1330:      * If parameter $columns is either a single column name or an array of column names
    1331:      * than only those columns are validated.
    1332:      *
    1333:      * NOTICE: This does not apply to primary or foreign keys for now.
    1334:      *
    1335:      * @param      ProductCategory $obj The object to validate.
    1336:      * @param      mixed $cols Column name or array of column names.
    1337:      *
    1338:      * @return mixed TRUE if all columns are valid or the error message of the first invalid column.
    1339:      */
    1340:     public static function doValidate($obj, $cols = null)
    1341:     {
    1342:         $columns = array();
    1343:
    1344:         if ($cols) {
    1345:             $dbMap = Propel::getDatabaseMap(ProductCategoryPeer::DATABASE_NAME);
    1346:             $tableMap = $dbMap->getTable(ProductCategoryPeer::TABLE_NAME);
    1347:
    1348:             if (! is_array($cols)) {
    1349:                 $cols = array($cols);
    1350:             }
    1351:
    1352:             foreach ($cols as $colName) {
    1353:                 if ($tableMap->hasColumn($colName)) {
    1354:                     $get = 'get' . $tableMap->getColumn($colName)->getPhpName();
    1355:                     $columns[$colName] = $obj->$get();
    1356:                 }
    1357:             }
    1358:         } else {
    1359:
    1360:         }
    1361:
    1362:         return BasePeer::doValidate(ProductCategoryPeer::DATABASE_NAME, ProductCategoryPeer::TABLE_NAME, $columns);
    1363:     }
    1364:
    1365:     /**
    1366:      * Retrieve object using using composite pkey values.
    1367:      * @param   int $product_id
    1368:      * @param   int $category_id
    1369:      * @param      PropelPDO $con
    1370:      * @return   ProductCategory
    1371:      */
    1372:     public static function retrieveByPK($product_id, $category_id, PropelPDO $con = null) {
    1373:         $_instancePoolKey = serialize(array((string) $product_id, (string) $category_id));
    1374:          if (null !== ($obj = ProductCategoryPeer::getInstanceFromPool($_instancePoolKey))) {
    1375:              return $obj;
    1376:         }
    1377:
    1378:         if ($con === null) {
    1379:             $con = Propel::getConnection(ProductCategoryPeer::DATABASE_NAME, Propel::CONNECTION_READ);
    1380:         }
    1381:         $criteria = new Criteria(ProductCategoryPeer::DATABASE_NAME);
    1382:         $criteria->add(ProductCategoryPeer::PRODUCT_ID, $product_id);
    1383:         $criteria->add(ProductCategoryPeer::CATEGORY_ID, $category_id);
    1384:         $v = ProductCategoryPeer::doSelect($criteria, $con);
    1385:
    1386:         return !empty($v) ? $v[0] : null;
    1387:     }
    1388: } // BaseProductCategoryPeer
    1389:
    1390: // This is the static code needed to register the TableMap for this table with the main Propel class.
    1391: //
    1392: BaseProductCategoryPeer::buildTableMap();
    1393:
    1394: