5 * Base static class for performing query and update operations on the 'medium' table.
9 * @package propel.generator.propel.om
11 abstract class BaseMediumPeer
14 /** the default database name for this class */
15 const DATABASE_NAME = 'mkrimi';
17 /** the table name for this class */
18 const TABLE_NAME = 'medium';
20 /** the related Propel class for this table */
21 const OM_CLASS = 'Medium';
23 /** the related TableMap class for this table */
24 const TM_CLASS = 'MediumTableMap';
26 /** The total number of columns. */
27 const NUM_COLUMNS = 8;
29 /** The number of lazy-loaded columns. */
30 const NUM_LAZY_LOAD_COLUMNS = 0;
32 /** The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS) */
33 const NUM_HYDRATE_COLUMNS = 8;
35 /** the column name for the id field */
36 const ID = 'medium.id';
38 /** the column name for the mod field */
39 const MOD = 'medium.mod';
41 /** the column name for the autor field */
42 const AUTOR = 'medium.autor';
44 /** the column name for the titel field */
45 const TITEL = 'medium.titel';
47 /** the column name for the eigentumer field */
48 const EIGENTUMER = 'medium.eigentumer';
50 /** the column name for the zz_bei field */
51 const ZZ_BEI = 'medium.zz_bei';
53 /** the column name for the kommentar field */
54 const KOMMENTAR = 'medium.kommentar';
56 /** the column name for the class_key field */
57 const CLASS_KEY = 'medium.class_key';
59 /** A key representing a particular subclass */
60 const CLASSKEY_1 = '1';
62 /** A key representing a particular subclass */
63 const CLASSKEY_KRIMI = '1';
65 /** A class that can be returned by this peer. */
66 const CLASSNAME_1 = 'Krimi';
68 /** A key representing a particular subclass */
69 const CLASSKEY_2 = '2';
71 /** A key representing a particular subclass */
72 const CLASSKEY_HORBUCH = '2';
74 /** A class that can be returned by this peer. */
75 const CLASSNAME_2 = 'Horbuch';
77 /** A key representing a particular subclass */
78 const CLASSKEY_3 = '3';
80 /** A key representing a particular subclass */
81 const CLASSKEY_ROMAN = '3';
83 /** A class that can be returned by this peer. */
84 const CLASSNAME_3 = 'Roman';
86 /** The default string format for model objects of the related table **/
87 const DEFAULT_STRING_FORMAT = 'YAML';
90 * An identity map to hold any loaded instances of Medium objects.
91 * This must be public so that other peer classes can access this when hydrating from JOIN
95 public static $instances = array();
99 * holds an array of fieldnames
101 * first dimension keys are the type constants
102 * e.g. MediumPeer::$fieldNames[MediumPeer::TYPE_PHPNAME][0] = 'Id'
104 protected static $fieldNames = array (
105 BasePeer::TYPE_PHPNAME => array ('Id', 'Mod', 'Autor', 'Titel', 'Eigentumer', 'ZzBei', 'Kommentar', 'ClassKey', ),
106 BasePeer::TYPE_STUDLYPHPNAME => array ('id', 'mod', 'autor', 'titel', 'eigentumer', 'zzBei', 'kommentar', 'classKey', ),
107 BasePeer::TYPE_COLNAME => array (MediumPeer::ID, MediumPeer::MOD, MediumPeer::AUTOR, MediumPeer::TITEL, MediumPeer::EIGENTUMER, MediumPeer::ZZ_BEI, MediumPeer::KOMMENTAR, MediumPeer::CLASS_KEY, ),
108 BasePeer::TYPE_RAW_COLNAME => array ('ID', 'MOD', 'AUTOR', 'TITEL', 'EIGENTUMER', 'ZZ_BEI', 'KOMMENTAR', 'CLASS_KEY', ),
109 BasePeer::TYPE_FIELDNAME => array ('id', 'mod', 'autor', 'titel', 'eigentumer', 'zz_bei', 'kommentar', 'class_key', ),
110 BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, )
114 * holds an array of keys for quick access to the fieldnames array
116 * first dimension keys are the type constants
117 * e.g. MediumPeer::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0
119 protected static $fieldKeys = array (
120 BasePeer::TYPE_PHPNAME => array ('Id' => 0, 'Mod' => 1, 'Autor' => 2, 'Titel' => 3, 'Eigentumer' => 4, 'ZzBei' => 5, 'Kommentar' => 6, 'ClassKey' => 7, ),
121 BasePeer::TYPE_STUDLYPHPNAME => array ('id' => 0, 'mod' => 1, 'autor' => 2, 'titel' => 3, 'eigentumer' => 4, 'zzBei' => 5, 'kommentar' => 6, 'classKey' => 7, ),
122 BasePeer::TYPE_COLNAME => array (MediumPeer::ID => 0, MediumPeer::MOD => 1, MediumPeer::AUTOR => 2, MediumPeer::TITEL => 3, MediumPeer::EIGENTUMER => 4, MediumPeer::ZZ_BEI => 5, MediumPeer::KOMMENTAR => 6, MediumPeer::CLASS_KEY => 7, ),
123 BasePeer::TYPE_RAW_COLNAME => array ('ID' => 0, 'MOD' => 1, 'AUTOR' => 2, 'TITEL' => 3, 'EIGENTUMER' => 4, 'ZZ_BEI' => 5, 'KOMMENTAR' => 6, 'CLASS_KEY' => 7, ),
124 BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'mod' => 1, 'autor' => 2, 'titel' => 3, 'eigentumer' => 4, 'zz_bei' => 5, 'kommentar' => 6, 'class_key' => 7, ),
125 BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, )
129 * Translates a fieldname to another type
131 * @param string $name field name
132 * @param string $fromType One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
133 * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM
134 * @param string $toType One of the class type constants
135 * @return string translated name of the field.
136 * @throws PropelException - if the specified name could not be found in the fieldname mappings.
138 public static function translateFieldName($name, $fromType, $toType)
140 $toNames = MediumPeer::getFieldNames($toType);
141 $key = isset(MediumPeer::$fieldKeys[$fromType][$name]) ? MediumPeer::$fieldKeys[$fromType][$name] : null;
143 throw new PropelException("'$name' could not be found in the field names of type '$fromType'. These are: " . print_r(MediumPeer::$fieldKeys[$fromType], true));
146 return $toNames[$key];
150 * Returns an array of field names.
152 * @param string $type The type of fieldnames to return:
153 * One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
154 * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM
155 * @return array A list of field names
156 * @throws PropelException - if the type is not valid.
158 public static function getFieldNames($type = BasePeer::TYPE_PHPNAME)
160 if (!array_key_exists($type, MediumPeer::$fieldNames)) {
161 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.');
164 return MediumPeer::$fieldNames[$type];
168 * Convenience method which changes table.column to alias.column.
170 * Using this method you can maintain SQL abstraction while using column aliases.
172 * $c->addAlias("alias1", TablePeer::TABLE_NAME);
173 * $c->addJoin(TablePeer::alias("alias1", TablePeer::PRIMARY_KEY_COLUMN), TablePeer::PRIMARY_KEY_COLUMN);
175 * @param string $alias The alias for the current table.
176 * @param string $column The column name for current table. (i.e. MediumPeer::COLUMN_NAME).
179 public static function alias($alias, $column)
181 return str_replace(MediumPeer::TABLE_NAME.'.', $alias.'.', $column);
185 * Add all the columns needed to create a new object.
187 * Note: any columns that were marked with lazyLoad="true" in the
188 * XML schema will not be added to the select list and only loaded
191 * @param Criteria $criteria object containing the columns to add.
192 * @param string $alias optional table alias
193 * @throws PropelException Any exceptions caught during processing will be
194 * rethrown wrapped into a PropelException.
196 public static function addSelectColumns(Criteria $criteria, $alias = null)
198 if (null === $alias) {
199 $criteria->addSelectColumn(MediumPeer::ID);
200 $criteria->addSelectColumn(MediumPeer::MOD);
201 $criteria->addSelectColumn(MediumPeer::AUTOR);
202 $criteria->addSelectColumn(MediumPeer::TITEL);
203 $criteria->addSelectColumn(MediumPeer::EIGENTUMER);
204 $criteria->addSelectColumn(MediumPeer::ZZ_BEI);
205 $criteria->addSelectColumn(MediumPeer::KOMMENTAR);
206 $criteria->addSelectColumn(MediumPeer::CLASS_KEY);
208 $criteria->addSelectColumn($alias . '.id');
209 $criteria->addSelectColumn($alias . '.mod');
210 $criteria->addSelectColumn($alias . '.autor');
211 $criteria->addSelectColumn($alias . '.titel');
212 $criteria->addSelectColumn($alias . '.eigentumer');
213 $criteria->addSelectColumn($alias . '.zz_bei');
214 $criteria->addSelectColumn($alias . '.kommentar');
215 $criteria->addSelectColumn($alias . '.class_key');
220 * Returns the number of rows matching criteria.
222 * @param Criteria $criteria
223 * @param boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
224 * @param PropelPDO $con
225 * @return int Number of matching rows.
227 public static function doCount(Criteria $criteria, $distinct = false, PropelPDO $con = null)
229 // we may modify criteria, so copy it first
230 $criteria = clone $criteria;
232 // We need to set the primary table name, since in the case that there are no WHERE columns
233 // it will be impossible for the BasePeer::createSelectSql() method to determine which
234 // tables go into the FROM clause.
235 $criteria->setPrimaryTableName(MediumPeer::TABLE_NAME);
237 if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
238 $criteria->setDistinct();
241 if (!$criteria->hasSelectClause()) {
242 MediumPeer::addSelectColumns($criteria);
245 $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
246 $criteria->setDbName(MediumPeer::DATABASE_NAME); // Set the correct dbName
249 $con = Propel::getConnection(MediumPeer::DATABASE_NAME, Propel::CONNECTION_READ);
251 // BasePeer returns a PDOStatement
252 $stmt = BasePeer::doCount($criteria, $con);
254 if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
255 $count = (int) $row[0];
257 $count = 0; // no rows returned; we infer that means 0 matches.
259 $stmt->closeCursor();
264 * Selects one object from the DB.
266 * @param Criteria $criteria object used to create the SELECT statement.
267 * @param PropelPDO $con
269 * @throws PropelException Any exceptions caught during processing will be
270 * rethrown wrapped into a PropelException.
272 public static function doSelectOne(Criteria $criteria, PropelPDO $con = null)
274 $critcopy = clone $criteria;
275 $critcopy->setLimit(1);
276 $objects = MediumPeer::doSelect($critcopy, $con);
284 * Selects several row from the DB.
286 * @param Criteria $criteria The Criteria object used to build the SELECT statement.
287 * @param PropelPDO $con
288 * @return array Array of selected Objects
289 * @throws PropelException Any exceptions caught during processing will be
290 * rethrown wrapped into a PropelException.
292 public static function doSelect(Criteria $criteria, PropelPDO $con = null)
294 return MediumPeer::populateObjects(MediumPeer::doSelectStmt($criteria, $con));
297 * Prepares the Criteria object and uses the parent doSelect() method to execute a PDOStatement.
299 * Use this method directly if you want to work with an executed statement directly (for example
300 * to perform your own object hydration).
302 * @param Criteria $criteria The Criteria object used to build the SELECT statement.
303 * @param PropelPDO $con The connection to use
304 * @throws PropelException Any exceptions caught during processing will be
305 * rethrown wrapped into a PropelException.
306 * @return PDOStatement The executed PDOStatement object.
307 * @see BasePeer::doSelect()
309 public static function doSelectStmt(Criteria $criteria, PropelPDO $con = null)
312 $con = Propel::getConnection(MediumPeer::DATABASE_NAME, Propel::CONNECTION_READ);
315 if (!$criteria->hasSelectClause()) {
316 $criteria = clone $criteria;
317 MediumPeer::addSelectColumns($criteria);
320 // Set the correct dbName
321 $criteria->setDbName(MediumPeer::DATABASE_NAME);
323 // BasePeer returns a PDOStatement
324 return BasePeer::doSelect($criteria, $con);
327 * Adds an object to the instance pool.
329 * Propel keeps cached copies of objects in an instance pool when they are retrieved
330 * from the database. In some cases -- especially when you override doSelect*()
331 * methods in your stub classes -- you may need to explicitly add objects
332 * to the cache in order to ensure that the same objects are always returned by doSelect*()
333 * and retrieveByPK*() calls.
335 * @param Medium $obj A Medium object.
336 * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
338 public static function addInstanceToPool($obj, $key = null)
340 if (Propel::isInstancePoolingEnabled()) {
342 $key = (string) $obj->getId();
344 MediumPeer::$instances[$key] = $obj;
349 * Removes an object from the instance pool.
351 * Propel keeps cached copies of objects in an instance pool when they are retrieved
352 * from the database. In some cases -- especially when you override doDelete
353 * methods in your stub classes -- you may need to explicitly remove objects
354 * from the cache in order to prevent returning objects that no longer exist.
356 * @param mixed $value A Medium object or a primary key value.
359 * @throws PropelException - if the value is invalid.
361 public static function removeInstanceFromPool($value)
363 if (Propel::isInstancePoolingEnabled() && $value !== null) {
364 if (is_object($value) && $value instanceof Medium) {
365 $key = (string) $value->getId();
366 } elseif (is_scalar($value)) {
367 // assume we've been passed a primary key
368 $key = (string) $value;
370 $e = new PropelException("Invalid value passed to removeInstanceFromPool(). Expected primary key or Medium object; got " . (is_object($value) ? get_class($value) . ' object.' : var_export($value,true)));
374 unset(MediumPeer::$instances[$key]);
376 } // removeInstanceFromPool()
379 * 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.
381 * For tables with a single-column primary key, that simple pkey value will be returned. For tables with
382 * a multi-column primary key, a serialize()d version of the primary key will be returned.
384 * @param string $key The key (@see getPrimaryKeyHash()) for this instance.
385 * @return Medium Found object or null if 1) no instance exists for specified key or 2) instance pooling has been disabled.
386 * @see getPrimaryKeyHash()
388 public static function getInstanceFromPool($key)
390 if (Propel::isInstancePoolingEnabled()) {
391 if (isset(MediumPeer::$instances[$key])) {
392 return MediumPeer::$instances[$key];
396 return null; // just to be explicit
400 * Clear the instance pool.
404 public static function clearInstancePool($and_clear_all_references = false)
406 if ($and_clear_all_references) {
407 foreach (MediumPeer::$instances as $instance) {
408 $instance->clearAllReferences(true);
411 MediumPeer::$instances = array();
415 * Method to invalidate the instance pool of all tables related to medium
416 * by a foreign key with ON DELETE CASCADE
418 public static function clearRelatedInstancePool()
423 * 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.
425 * For tables with a single-column primary key, that simple pkey value will be returned. For tables with
426 * a multi-column primary key, a serialize()d version of the primary key will be returned.
428 * @param array $row PropelPDO resultset row.
429 * @param int $startcol The 0-based offset for reading from the resultset row.
430 * @return string A string version of PK or null if the components of primary key in result array are all null.
432 public static function getPrimaryKeyHashFromRow($row, $startcol = 0)
434 // If the PK cannot be derived from the row, return null.
435 if ($row[$startcol] === null) {
439 return (string) $row[$startcol];
443 * Retrieves the primary key from the DB resultset row
444 * For tables with a single-column primary key, that simple pkey value will be returned. For tables with
445 * a multi-column primary key, an array of the primary key columns will be returned.
447 * @param array $row PropelPDO resultset row.
448 * @param int $startcol The 0-based offset for reading from the resultset row.
449 * @return mixed The primary key of the row
451 public static function getPrimaryKeyFromRow($row, $startcol = 0)
454 return (int) $row[$startcol];
458 * The returned array will contain objects of the default type or
459 * objects that inherit from the default.
461 * @throws PropelException Any exceptions caught during processing will be
462 * rethrown wrapped into a PropelException.
464 public static function populateObjects(PDOStatement $stmt)
468 // populate the object(s)
469 while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
470 $key = MediumPeer::getPrimaryKeyHashFromRow($row, 0);
471 if (null !== ($obj = MediumPeer::getInstanceFromPool($key))) {
472 // We no longer rehydrate the object, since this can cause data loss.
473 // See http://www.propelorm.org/ticket/509
474 // $obj->hydrate($row, 0, true); // rehydrate
477 // class must be set each time from the record row
478 $cls = MediumPeer::getOMClass($row, 0);
479 $cls = substr('.'.$cls, strrpos('.'.$cls, '.') + 1);
483 MediumPeer::addInstanceToPool($obj, $key);
486 $stmt->closeCursor();
491 * Populates an object of the default type or an object that inherit from the default.
493 * @param array $row PropelPDO resultset row.
494 * @param int $startcol The 0-based offset for reading from the resultset row.
495 * @throws PropelException Any exceptions caught during processing will be
496 * rethrown wrapped into a PropelException.
497 * @return array (Medium object, last column rank)
499 public static function populateObject($row, $startcol = 0)
501 $key = MediumPeer::getPrimaryKeyHashFromRow($row, $startcol);
502 if (null !== ($obj = MediumPeer::getInstanceFromPool($key))) {
503 // We no longer rehydrate the object, since this can cause data loss.
504 // See http://www.propelorm.org/ticket/509
505 // $obj->hydrate($row, $startcol, true); // rehydrate
506 $col = $startcol + MediumPeer::NUM_HYDRATE_COLUMNS;
508 $cls = MediumPeer::getOMClass($row, $startcol);
510 $col = $obj->hydrate($row, $startcol);
511 MediumPeer::addInstanceToPool($obj, $key);
514 return array($obj, $col);
518 * Returns the TableMap related to this peer.
519 * This method is not needed for general use but a specific application could have a need.
521 * @throws PropelException Any exceptions caught during processing will be
522 * rethrown wrapped into a PropelException.
524 public static function getTableMap()
526 return Propel::getDatabaseMap(MediumPeer::DATABASE_NAME)->getTable(MediumPeer::TABLE_NAME);
530 * Add a TableMap instance to the database for this peer class.
532 public static function buildTableMap()
534 $dbMap = Propel::getDatabaseMap(BaseMediumPeer::DATABASE_NAME);
535 if (!$dbMap->hasTable(BaseMediumPeer::TABLE_NAME)) {
536 $dbMap->addTableObject(new \MediumTableMap());
541 * The returned Class will contain objects of the default type or
542 * objects that inherit from the default.
544 * @param array $row PropelPDO result row.
545 * @param int $colnum Column to examine for OM class information (first is 0).
546 * @throws PropelException Any exceptions caught during processing will be
547 * rethrown wrapped into a PropelException.
549 public static function getOMClass($row = 0, $colnum = 0)
554 $classKey = $row[$colnum + 7];
558 case MediumPeer::CLASSKEY_1:
559 $omClass = MediumPeer::CLASSNAME_1;
562 case MediumPeer::CLASSKEY_2:
563 $omClass = MediumPeer::CLASSNAME_2;
566 case MediumPeer::CLASSKEY_3:
567 $omClass = MediumPeer::CLASSNAME_3;
571 $omClass = MediumPeer::OM_CLASS;
575 } catch (Exception $e) {
576 throw new PropelException('Unable to get OM class.', $e);
583 * Performs an INSERT on the database, given a Medium or Criteria object.
585 * @param mixed $values Criteria or Medium object containing data that is used to create the INSERT statement.
586 * @param PropelPDO $con the PropelPDO connection to use
587 * @return mixed The new primary key.
588 * @throws PropelException Any exceptions caught during processing will be
589 * rethrown wrapped into a PropelException.
591 public static function doInsert($values, PropelPDO $con = null)
594 $con = Propel::getConnection(MediumPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
597 if ($values instanceof Criteria) {
598 $criteria = clone $values; // rename for clarity
600 $criteria = $values->buildCriteria(); // build Criteria from Medium object
603 if ($criteria->containsKey(MediumPeer::ID) && $criteria->keyContainsValue(MediumPeer::ID) ) {
604 throw new PropelException('Cannot insert a value for auto-increment primary key ('.MediumPeer::ID.')');
608 // Set the correct dbName
609 $criteria->setDbName(MediumPeer::DATABASE_NAME);
612 // use transaction because $criteria could contain info
613 // for more than one table (I guess, conceivably)
614 $con->beginTransaction();
615 $pk = BasePeer::doInsert($criteria, $con);
617 } catch (Exception $e) {
626 * Performs an UPDATE on the database, given a Medium or Criteria object.
628 * @param mixed $values Criteria or Medium object containing data that is used to create the UPDATE statement.
629 * @param PropelPDO $con The connection to use (specify PropelPDO connection object to exert more control over transactions).
630 * @return int The number of affected rows (if supported by underlying database driver).
631 * @throws PropelException Any exceptions caught during processing will be
632 * rethrown wrapped into a PropelException.
634 public static function doUpdate($values, PropelPDO $con = null)
637 $con = Propel::getConnection(MediumPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
640 $selectCriteria = new Criteria(MediumPeer::DATABASE_NAME);
642 if ($values instanceof Criteria) {
643 $criteria = clone $values; // rename for clarity
645 $comparison = $criteria->getComparison(MediumPeer::ID);
646 $value = $criteria->remove(MediumPeer::ID);
648 $selectCriteria->add(MediumPeer::ID, $value, $comparison);
650 $selectCriteria->setPrimaryTableName(MediumPeer::TABLE_NAME);
653 } else { // $values is Medium object
654 $criteria = $values->buildCriteria(); // gets full criteria
655 $selectCriteria = $values->buildPkeyCriteria(); // gets criteria w/ primary key(s)
658 // set the correct dbName
659 $criteria->setDbName(MediumPeer::DATABASE_NAME);
661 return BasePeer::doUpdate($selectCriteria, $criteria, $con);
665 * Deletes all rows from the medium table.
667 * @param PropelPDO $con the connection to use
668 * @return int The number of affected rows (if supported by underlying database driver).
669 * @throws PropelException
671 public static function doDeleteAll(PropelPDO $con = null)
674 $con = Propel::getConnection(MediumPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
676 $affectedRows = 0; // initialize var to track total num of affected rows
678 // use transaction because $criteria could contain info
679 // for more than one table or we could emulating ON DELETE CASCADE, etc.
680 $con->beginTransaction();
681 $affectedRows += BasePeer::doDeleteAll(MediumPeer::TABLE_NAME, $con, MediumPeer::DATABASE_NAME);
682 // Because this db requires some delete cascade/set null emulation, we have to
683 // clear the cached instance *after* the emulation has happened (since
684 // instances get re-added by the select statement contained therein).
685 MediumPeer::clearInstancePool();
686 MediumPeer::clearRelatedInstancePool();
689 return $affectedRows;
690 } catch (Exception $e) {
697 * Performs a DELETE on the database, given a Medium or Criteria object OR a primary key value.
699 * @param mixed $values Criteria or Medium object or primary key or array of primary keys
700 * which is used to create the DELETE statement
701 * @param PropelPDO $con the connection to use
702 * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows
703 * if supported by native driver or if emulated using Propel.
704 * @throws PropelException Any exceptions caught during processing will be
705 * rethrown wrapped into a PropelException.
707 public static function doDelete($values, PropelPDO $con = null)
710 $con = Propel::getConnection(MediumPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
713 if ($values instanceof Criteria) {
714 // invalidate the cache for all objects of this type, since we have no
715 // way of knowing (without running a query) what objects should be invalidated
716 // from the cache based on this Criteria.
717 MediumPeer::clearInstancePool();
718 // rename for clarity
719 $criteria = clone $values;
720 } elseif ($values instanceof Medium) { // it's a model object
721 // invalidate the cache for this single object
722 MediumPeer::removeInstanceFromPool($values);
723 // create criteria based on pk values
724 $criteria = $values->buildPkeyCriteria();
725 } else { // it's a primary key, or an array of pks
726 $criteria = new Criteria(MediumPeer::DATABASE_NAME);
727 $criteria->add(MediumPeer::ID, (array) $values, Criteria::IN);
728 // invalidate the cache for this object(s)
729 foreach ((array) $values as $singleval) {
730 MediumPeer::removeInstanceFromPool($singleval);
734 // Set the correct dbName
735 $criteria->setDbName(MediumPeer::DATABASE_NAME);
737 $affectedRows = 0; // initialize var to track total num of affected rows
740 // use transaction because $criteria could contain info
741 // for more than one table or we could emulating ON DELETE CASCADE, etc.
742 $con->beginTransaction();
744 $affectedRows += BasePeer::doDelete($criteria, $con);
745 MediumPeer::clearRelatedInstancePool();
748 return $affectedRows;
749 } catch (Exception $e) {
756 * Validates all modified columns of given Medium object.
757 * If parameter $columns is either a single column name or an array of column names
758 * than only those columns are validated.
760 * NOTICE: This does not apply to primary or foreign keys for now.
762 * @param Medium $obj The object to validate.
763 * @param mixed $cols Column name or array of column names.
765 * @return mixed TRUE if all columns are valid or the error message of the first invalid column.
767 public static function doValidate($obj, $cols = null)
772 $dbMap = Propel::getDatabaseMap(MediumPeer::DATABASE_NAME);
773 $tableMap = $dbMap->getTable(MediumPeer::TABLE_NAME);
775 if (! is_array($cols)) {
776 $cols = array($cols);
779 foreach ($cols as $colName) {
780 if ($tableMap->hasColumn($colName)) {
781 $get = 'get' . $tableMap->getColumn($colName)->getPhpName();
782 $columns[$colName] = $obj->$get();
789 return BasePeer::doValidate(MediumPeer::DATABASE_NAME, MediumPeer::TABLE_NAME, $columns);
793 * Retrieve a single object by pkey.
795 * @param int $pk the primary key.
796 * @param PropelPDO $con the connection to use
799 public static function retrieveByPK($pk, PropelPDO $con = null)
802 if (null !== ($obj = MediumPeer::getInstanceFromPool((string) $pk))) {
807 $con = Propel::getConnection(MediumPeer::DATABASE_NAME, Propel::CONNECTION_READ);
810 $criteria = new Criteria(MediumPeer::DATABASE_NAME);
811 $criteria->add(MediumPeer::ID, $pk);
813 $v = MediumPeer::doSelect($criteria, $con);
815 return !empty($v) > 0 ? $v[0] : null;
819 * Retrieve multiple objects by pkey.
821 * @param array $pks List of primary keys
822 * @param PropelPDO $con the connection to use
824 * @throws PropelException Any exceptions caught during processing will be
825 * rethrown wrapped into a PropelException.
827 public static function retrieveByPKs($pks, PropelPDO $con = null)
830 $con = Propel::getConnection(MediumPeer::DATABASE_NAME, Propel::CONNECTION_READ);
837 $criteria = new Criteria(MediumPeer::DATABASE_NAME);
838 $criteria->add(MediumPeer::ID, $pks, Criteria::IN);
839 $objs = MediumPeer::doSelect($criteria, $con);
847 // This is the static code needed to register the TableMap for this table with the main Propel class.
849 BaseMediumPeer::buildTableMap();