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