[WIP] Peer #290

Closed
wants to merge 2 commits into
from
Jump to file
+666 −621
Split
View
2 src/Propel/Generator/Behavior/Archivable/ArchivableBehaviorQueryBuilderModifier.php
@@ -98,7 +98,7 @@ protected function addArchive($builder)
{
return $this->behavior->renderTemplate('queryArchive', array(
'archiveTablePhpName' => $this->behavior->getArchiveTablePhpName($builder),
- 'modelPeerName' => $builder->getPeerClassName(),
+ 'modelTableMap' => $builder->getTableMapClass(),
));
}
View
2 src/Propel/Generator/Behavior/Archivable/templates/queryArchive.php
@@ -23,7 +23,7 @@ public function archive($con = null, $useLittleMemory = true)
$criteria->setFormatter(ModelCriteria::FORMAT_ON_DEMAND);
}
if ($con === null) {
- $con = Propel::getServiceContainer()->getWriteConnection(<?php echo $modelPeerName ?>::DATABASE_NAME);
+ $con = Propel::getServiceContainer()->getWriteConnection(<?php echo $modelTableMap ?>::DATABASE_NAME);
}
$con->beginTransaction();
try {
View
8 src/Propel/Generator/Builder/Om/AbstractOMBuilder.php
@@ -782,6 +782,14 @@ public function renderTemplate($filename, $vars = array(), $templateDir = '/temp
}
/**
+ * @return string
+ */
+ public function getTableMapClass()
+ {
+ return $this->getStubObjectBuilder()->getUnqualifiedClassName() . 'TableMap';
+ }
+
+ /**
* Most of the code comes from the PHP-CS-Fixer project
*/
private function clean($content)
View
58 src/Propel/Generator/Builder/Om/ObjectBuilder.php
@@ -258,6 +258,8 @@ protected function addClassBody(&$script)
$this->declareClassFromBuilder($this->getStubObjectBuilder());
$this->declareClassFromBuilder($this->getStubPeerBuilder());
$this->declareClassFromBuilder($this->getStubQueryBuilder());
+ $this->declareClassFromBuilder($this->getTableMapBuilder());
+
$this->declareClasses(
'\Exception',
'\PDO',
@@ -271,7 +273,8 @@ protected function addClassBody(&$script)
'\Propel\Runtime\ActiveRecord\ActiveRecordInterface',
'\Propel\Runtime\Parser\AbstractParser',
'\Propel\Runtime\Propel',
- '\Propel\Runtime\Util\BasePeer'
+ '\Propel\Runtime\Util\BasePeer',
+ '\Propel\Runtime\Map\TableMap'
);
$table = $this->getTable();
@@ -379,6 +382,11 @@ protected function addConstants(&$script)
* Peer class name
*/
const PEER = '" . addslashes($this->getStubPeerBuilder()->getFullyQualifiedClassName()) . "';
+
+ /**
+ * TableMap class name
+ */
+ const TABLE_MAP = '" . addslashes($this->getTableMapBuilder()->getFullyQualifiedClassName()) . "';
";
}
@@ -2061,7 +2069,7 @@ protected function addHydrateBody(&$script)
\$this->ensureConsistency();
}
- return \$startcol + $n; // $n = ".$this->getPeerClassName()."::NUM_HYDRATE_COLUMNS.
+ return \$startcol + $n; // $n = ".$this->getTableMapClass()."::NUM_HYDRATE_COLUMNS.
} catch (Exception \$e) {
throw new PropelException(\"Error populating ".$this->getStubObjectBuilder()->getClassName()." object\", 0, \$e);
@@ -2130,7 +2138,7 @@ public function buildPkeyCriteria()
protected function addBuildPkeyCriteriaBody(&$script)
{
$script .= "
- \$criteria = new Criteria(".$this->getPeerClassName()."::DATABASE_NAME);";
+ \$criteria = new Criteria(".$this->getTableMapClass()."::DATABASE_NAME);";
foreach ($this->getTable()->getPrimaryKey() as $col) {
$clo = strtolower($col->getName());
$script .= "
@@ -2199,7 +2207,7 @@ public function buildCriteria()
protected function addBuildCriteriaBody(&$script)
{
$script .= "
- \$criteria = new Criteria(".$this->getPeerClassName()."::DATABASE_NAME);
+ \$criteria = new Criteria(".$this->getTableMapClass()."::DATABASE_NAME);
";
foreach ($this->getTable()->getColumns() as $col) {
$clo = strtolower($col->getName());
@@ -2241,9 +2249,9 @@ protected function addToArray(&$script)
* You can specify the key type of the array by passing one of the class
* type constants.
*
- * @param string \$keyType (optional) One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
- * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
- * Defaults to BasePeer::$defaultKeyType.
+ * @param string \$keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME,
+ * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
+ * Defaults to TableMap::$defaultKeyType.
* @param boolean \$includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE.
* @param array \$alreadyDumpedObjects List of objects to skip to avoid recursion";
if ($hasFks) {
@@ -2254,7 +2262,7 @@ protected function addToArray(&$script)
*
* @return array an associative array containing the field names (as keys) and field values
*/
- public function toArray(\$keyType = BasePeer::$defaultKeyType, \$includeLazyLoadColumns = true, \$alreadyDumpedObjects = array()" . ($hasFks ? ", \$includeForeignObjects = false" : '') . ")
+ public function toArray(\$keyType = TableMap::$defaultKeyType, \$includeLazyLoadColumns = true, \$alreadyDumpedObjects = array()" . ($hasFks ? ", \$includeForeignObjects = false" : '') . ")
{
if (isset(\$alreadyDumpedObjects['$objectClassName'][$pkGetter])) {
return '*RECURSION*';
@@ -2331,9 +2339,9 @@ protected function addGetByNameComment(&$script)
*
* @param string \$name name
* @param string \$type The type of fieldname the \$name is of:
- * one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
- * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
- * Defaults to BasePeer::$defaultKeyType.
+ * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME
+ * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
+ * Defaults to TableMap::$defaultKeyType.
* @return mixed Value of field.
*/";
}
@@ -2347,7 +2355,7 @@ protected function addGetByNameOpen(&$script)
{
$defaultKeyType = $this->getDefaultKeyType();
$script .= "
- public function getByName(\$name, \$type = BasePeer::$defaultKeyType)
+ public function getByName(\$name, \$type = TableMap::$defaultKeyType)
{";
}
@@ -2359,7 +2367,7 @@ public function getByName(\$name, \$type = BasePeer::$defaultKeyType)
protected function addGetByNameBody(&$script)
{
$script .= "
- \$pos = ".$this->getPeerClassName()."::translateFieldName(\$name, \$type, BasePeer::TYPE_NUM);
+ \$pos = ".$this->getPeerClassName()."::translateFieldName(\$name, \$type, TableMap::TYPE_NUM);
\$field = \$this->getByPosition(\$pos);";
}
@@ -2466,14 +2474,14 @@ protected function addSetByName(&$script)
* @param string \$name peer name
* @param mixed \$value field value
* @param string \$type The type of fieldname the \$name is of:
- * one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
- * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
- * Defaults to BasePeer::$defaultKeyType.
+ * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME
+ * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
+ * Defaults to TableMap::$defaultKeyType.
* @return void
*/
- public function setByName(\$name, \$value, \$type = BasePeer::$defaultKeyType)
+ public function setByName(\$name, \$value, \$type = TableMap::$defaultKeyType)
{
- \$pos = ".$this->getPeerClassName()."::translateFieldName(\$name, \$type, BasePeer::TYPE_NUM);
+ \$pos = ".$this->getPeerClassName()."::translateFieldName(\$name, \$type, TableMap::TYPE_NUM);
return \$this->setByPosition(\$pos, \$value);
}
@@ -2541,15 +2549,15 @@ protected function addFromArray(&$script)
* array. If so the setByName() method is called for that column.
*
* You can specify the key type of the array by additionally passing one
- * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
- * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
- * The default key type is the column's BasePeer::$defaultKeyType.
+ * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME,
+ * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
+ * The default key type is the column's TableMap::$defaultKeyType.
*
* @param array \$arr An array to populate the object from.
* @param string \$keyType The type of keys the array uses.
* @return void
*/
- public function fromArray(\$arr, \$keyType = BasePeer::$defaultKeyType)
+ public function fromArray(\$arr, \$keyType = TableMap::$defaultKeyType)
{
\$keys = ".$this->getPeerClassName()."::getFieldNames(\$keyType);
";
@@ -2620,7 +2628,7 @@ protected function addDeleteBody(&$script)
}
if (\$con === null) {
- \$con = Propel::getServiceContainer()->getWriteConnection(".$this->getPeerClassName()."::DATABASE_NAME);
+ \$con = Propel::getServiceContainer()->getWriteConnection(".$this->getTableMapClass()."::DATABASE_NAME);
}
\$con->beginTransaction();
@@ -2704,7 +2712,7 @@ public function reload(\$deep = false, ConnectionInterface \$con = null)
}
if (\$con === null) {
- \$con = Propel::getServiceContainer()->getReadConnection(".$this->getPeerClassName()."::DATABASE_NAME);
+ \$con = Propel::getServiceContainer()->getReadConnection(".$this->getTableMapClass()."::DATABASE_NAME);
}
// We don't need to alter the object instance pool; we're just modifying this instance
@@ -4666,7 +4674,7 @@ protected function addSaveBody(&$script)
}
if (\$con === null) {
- \$con = Propel::getServiceContainer()->getWriteConnection(".$this->getPeerClassName()."::DATABASE_NAME);
+ \$con = Propel::getServiceContainer()->getWriteConnection(".$this->getTableMapClass()."::DATABASE_NAME);
}
\$con->beginTransaction();
View
190 src/Propel/Generator/Builder/Om/PeerBuilder.php
@@ -144,6 +144,7 @@ protected function addClassBody(&$script)
'\Propel\Runtime\Connection\StatementInterface',
'\Propel\Runtime\Exception\PropelException',
'\Propel\Runtime\Util\BasePeer',
+ '\Propel\Runtime\Map\TableMap',
'\Propel\Runtime\ActiveQuery\Criteria',
'\PDO'
);
@@ -184,14 +185,6 @@ protected function addStaticTableMapRegistration(&$script)
/**
* @return string
*/
- public function getTableMapClass()
- {
- return $this->getStubObjectBuilder()->getUnqualifiedClassName() . 'TableMap';
- }
-
- /**
- * @return string
- */
public function getTablePhpName()
{
return ($this->getTable()->isAbstract() ? '' : $this->getClassNameFromBuilder($this->getStubObjectBuilder()));
@@ -204,34 +197,6 @@ public function getTablePhpName()
*/
protected function addConstantsAndAttributes(&$script)
{
- $dbName = $this->getDatabase()->getName();
- $tableName = $this->getTable()->getName();
- $tablePhpName = $this->getTable()->isAbstract() ? '' : addslashes($this->getStubObjectBuilder()->getFullyQualifiedClassName());
- $script .= "
- /** the default database name for this class */
- const DATABASE_NAME = '$dbName';
-
- /** the table name for this class */
- const TABLE_NAME = '$tableName';
-
- /** the related Propel class for this table */
- const OM_CLASS = '$tablePhpName';
-
- /** A class that can be returned by this peer. */
- const CLASS_DEFAULT = '".$this->getStubObjectBuilder()->getClasspath()."';
-
- /** the related TableMap class for this table */
- const TM_CLASS = '".$this->getTableMapClass()."';
-
- /** The total number of columns. */
- const NUM_COLUMNS = ".$this->getTable()->getNumColumns().";
-
- /** The number of lazy-loaded columns. */
- const NUM_LAZY_LOAD_COLUMNS = ".$this->getTable()->getNumLazyLoadColumns().";
-
- /** The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS) */
- const NUM_HYDRATE_COLUMNS = ". ($this->getTable()->getNumColumns() - $this->getTable()->getNumLazyLoadColumns()) .";
-";
$this->addColumnNameConstants($script);
$this->addInheritanceColumnConstants($script);
if ($this->getTable()->hasEnumColumns()) {
@@ -324,32 +289,32 @@ protected function addFieldNamesAttribute(&$script)
* e.g. self::\$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
*/
protected static \$fieldNames = array (
- BasePeer::TYPE_PHPNAME => array (";
+ TableMap::TYPE_PHPNAME => array (";
foreach ($tableColumns as $col) {
$script .= "'".$col->getPhpName()."', ";
}
$script .= "),
- BasePeer::TYPE_STUDLYPHPNAME => array (";
+ TableMap::TYPE_STUDLYPHPNAME => array (";
foreach ($tableColumns as $col) {
$script .= "'".$col->getStudlyPhpName()."', ";
}
$script .= "),
- BasePeer::TYPE_COLNAME => array (";
+ TableMap::TYPE_COLNAME => array (";
foreach ($tableColumns as $col) {
$script .= $this->getColumnConstant($col, 'self').", ";
}
$script .= "),
- BasePeer::TYPE_RAW_COLNAME => array (";
+ TableMap::TYPE_RAW_COLNAME => array (";
foreach ($tableColumns as $col) {
$script .= "'" . $col->getConstantColumnName() . "', ";
}
$script .= "),
- BasePeer::TYPE_FIELDNAME => array (";
+ TableMap::TYPE_FIELDNAME => array (";
foreach ($tableColumns as $col) {
$script .= "'".$col->getName()."', ";
}
$script .= "),
- BasePeer::TYPE_NUM => array (";
+ TableMap::TYPE_NUM => array (";
foreach ($tableColumns as $num => $col) {
$script .= "$num, ";
}
@@ -372,35 +337,35 @@ protected function addFieldKeysAttribute(&$script)
* holds an array of keys for quick access to the fieldnames array
*
* first dimension keys are the type constants
- * e.g. self::\$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0
+ * e.g. self::\$fieldNames[TableMap::TYPE_PHPNAME]['Id'] = 0
*/
protected static \$fieldKeys = array (
- BasePeer::TYPE_PHPNAME => array (";
+ TableMap::TYPE_PHPNAME => array (";
foreach ($tableColumns as $num => $col) {
$script .= "'".$col->getPhpName()."' => $num, ";
}
$script .= "),
- BasePeer::TYPE_STUDLYPHPNAME => array (";
+ TableMap::TYPE_STUDLYPHPNAME => array (";
foreach ($tableColumns as $num => $col) {
$script .= "'".$col->getStudlyPhpName()."' => $num, ";
}
$script .= "),
- BasePeer::TYPE_COLNAME => array (";
+ TableMap::TYPE_COLNAME => array (";
foreach ($tableColumns as $num => $col) {
$script .= $this->getColumnConstant($col, 'self')." => $num, ";
}
$script .= "),
- BasePeer::TYPE_RAW_COLNAME => array (";
+ TableMap::TYPE_RAW_COLNAME => array (";
foreach ($tableColumns as $num => $col) {
$script .= "'" . $col->getConstantColumnName() . "' => $num, ";
}
$script .= "),
- BasePeer::TYPE_FIELDNAME => array (";
+ TableMap::TYPE_FIELDNAME => array (";
foreach ($tableColumns as $num => $col) {
$script .= "'".$col->getName()."' => $num, ";
}
$script .= "),
- BasePeer::TYPE_NUM => array (";
+ TableMap::TYPE_NUM => array (";
foreach ($tableColumns as $num => $col) {
$script .= "$num, ";
}
@@ -445,15 +410,15 @@ protected function addGetFieldNames(&$script)
* Returns an array of field names.
*
* @param string \$type The type of fieldnames to return:
- * One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
- * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM
+ * One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME
+ * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM
* @return array A list of field names
* @throws PropelException
*/
- public static function getFieldNames(\$type = BasePeer::TYPE_PHPNAME)
+ public static function getFieldNames(\$type = TableMap::TYPE_PHPNAME)
{
if (!array_key_exists(\$type, self::\$fieldNames)) {
- 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.');
+ throw new PropelException('Method getFieldNames() expects the parameter \$type to be one of the class constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME, TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. ' . \$type . ' was given.');
}
return self::\$fieldNames[\$type];
@@ -472,8 +437,8 @@ protected function addTranslateFieldName(&$script)
* Translates a fieldname to another type
*
* @param string \$name field name
- * @param string \$fromType One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
- * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM
+ * @param string \$fromType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME
+ * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM
* @param string \$toType One of the class type constants
* @return string translated name of the field.
* @throws PropelException - if the specified name could not be found in the fieldname mappings.
@@ -543,8 +508,8 @@ protected function addBuildTableMap(&$script)
*/
public static function buildTableMap()
{
- \$dbMap = Propel::getServiceContainer()->getDatabaseMap(static::DATABASE_NAME);
- if (!\$dbMap->hasTable(static::TABLE_NAME)) {
+ \$dbMap = Propel::getServiceContainer()->getDatabaseMap(" . $this->getTableMapClass() . "::DATABASE_NAME);
+ if (!\$dbMap->hasTable(" . $this->getTableMapClass() . "::TABLE_NAME)) {
\$dbMap->addTableObject(new ".$this->getTableMapClass()."());
}
}
@@ -605,12 +570,12 @@ protected function addAlias(&$script)
* \$c->addJoin(TablePeer::alias(\"alias1\", TablePeer::PRIMARY_KEY_COLUMN), TablePeer::PRIMARY_KEY_COLUMN);
* </code>
* @param string \$alias The alias for the current table.
- * @param string \$column The column name for current table. (i.e. ".$this->getPeerClassName(true)."::COLUMN_NAME).
+ * @param string \$column The column name for current table. (i.e. ".$this->getTableMapClass()."::COLUMN_NAME).
* @return string
*/
public static function alias(\$alias, \$column)
{
- return str_replace(static::TABLE_NAME.'.', \$alias.'.', \$column);
+ return str_replace(" . $this->getTableMapClass() . "::TABLE_NAME.'.', \$alias.'.', \$column);
}
";
}
@@ -681,7 +646,7 @@ public static function doCount(Criteria \$criteria, \$distinct = false, Connecti
// We need to set the primary table name, since in the case that there are no WHERE columns
// it will be impossible for the BasePeer::createSelectSql() method to determine which
// tables go into the FROM clause.
- \$criteria->setPrimaryTableName(static::TABLE_NAME);
+ \$criteria->setPrimaryTableName(" . $this->getTableMapClass() . "::TABLE_NAME);
if (\$distinct && !in_array(Criteria::DISTINCT, \$criteria->getSelectModifiers())) {
\$criteria->setDistinct();
@@ -692,10 +657,10 @@ public static function doCount(Criteria \$criteria, \$distinct = false, Connecti
}
\$criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
- \$criteria->setDbName(self::DATABASE_NAME); // Set the correct dbName
+ \$criteria->setDbName(" . $this->getTableMapClass() . "::DATABASE_NAME); // Set the correct dbName
if (null === \$con) {
- \$con = Propel::getServiceContainer()->getReadConnection(static::DATABASE_NAME);
+ \$con = Propel::getServiceContainer()->getReadConnection(" . $this->getTableMapClass() . "::DATABASE_NAME);
}";
// apply behaviors
@@ -790,7 +755,7 @@ protected function addDoSelectStmt(&$script)
public static function doSelectStmt(Criteria \$criteria, ConnectionInterface \$con = null)
{
if (null === \$con) {
- \$con = Propel::getServiceContainer()->getReadConnection(static::DATABASE_NAME);
+ \$con = Propel::getServiceContainer()->getReadConnection(" . $this->getTableMapClass() . "::DATABASE_NAME);
}
if (!\$criteria->hasSelectClause()) {
@@ -799,7 +764,7 @@ public static function doSelectStmt(Criteria \$criteria, ConnectionInterface \$c
}
// Set the correct dbName
- \$criteria->setDbName(self::DATABASE_NAME);";
+ \$criteria->setDbName(" . $this->getTableMapClass() . "::DATABASE_NAME);";
// apply behaviors
if ($this->hasBehaviorModifier('preSelect')) {
$this->applyBehaviorModifier('preSelect', $script);
@@ -1211,20 +1176,20 @@ public static function populateObject(\$row, \$startcol = 0)
// We no longer rehydrate the object, since this can cause data loss.
// See http://www.propelorm.org/ticket/509
// \$obj->hydrate(\$row, \$startcol, true); // rehydrate
- \$col = \$startcol + static::NUM_HYDRATE_COLUMNS;";
+ \$col = \$startcol + " . $this->getTableMapClass() . "::NUM_HYDRATE_COLUMNS;";
if ($table->isAbstract()) {
$script .= "
} elseif (null == \$key) {
// empty resultset, probably from a left join
// since this table is abstract, we can't hydrate an empty object
\$obj = null;
- \$col = \$startcol + static::NUM_HYDRATE_COLUMNS;";
+ \$col = \$startcol + " . $this->getTableMapClass() . "::NUM_HYDRATE_COLUMNS;";
}
$script .= "
} else {";
if (!$table->getChildrenColumn()) {
$script .= "
- \$cls = static::OM_CLASS;";
+ \$cls = " . $this->getTableMapClass() . "::OM_CLASS;";
} else {
$script .= "
\$cls = static::getOMClass(\$row, \$startcol, false);";
@@ -1322,7 +1287,7 @@ protected function addGetOMClass_NoInheritance(&$script)
*/
public static function getOMClass(\$withPrefix = true)
{
- return \$withPrefix ? static::CLASS_DEFAULT : static::OM_CLASS;
+ return \$withPrefix ? " . $this->getTableMapClass() . "::CLASS_DEFAULT : " . $this->getTableMapClass() . "::OM_CLASS;
}
";
}
@@ -1353,6 +1318,8 @@ protected function addGetOMClass_NoInheritance_Abstract(&$script)
protected function addDoInsert(&$script)
{
$table = $this->getTable();
+ $tableMapClass = $this->getTableMapClass();
+
$script .= "
/**
* Performs an INSERT on the database, given a ".$this->getObjectClassName()." or Criteria object.
@@ -1366,7 +1333,7 @@ protected function addDoInsert(&$script)
public static function doInsert(\$values, ConnectionInterface \$con = null)
{
if (null === \$con) {
- \$con = Propel::getServiceContainer()->getWriteConnection(static::DATABASE_NAME);
+ \$con = Propel::getServiceContainer()->getWriteConnection(" . $tableMapClass . "::DATABASE_NAME);
}
if (\$values instanceof Criteria) {
@@ -1407,10 +1374,11 @@ public static function doInsert(\$values, ConnectionInterface \$con = null)
";
}
}
+
$script .= "
// Set the correct dbName
- \$criteria->setDbName(self::DATABASE_NAME);
+ \$criteria->setDbName(" . $this->getTableMapClass() . "::DATABASE_NAME);
try {
// use transaction because \$criteria could contain info
@@ -1448,10 +1416,10 @@ protected function addDoUpdate(&$script)
public static function doUpdate(\$values, ConnectionInterface \$con = null)
{
if (null === \$con) {
- \$con = Propel::getServiceContainer()->getWriteConnection(static::DATABASE_NAME);
+ \$con = Propel::getServiceContainer()->getWriteConnection(" . $this->getTableMapClass() . "::DATABASE_NAME);
}
- \$selectCriteria = new Criteria(self::DATABASE_NAME);
+ \$selectCriteria = new Criteria(" . $this->getTableMapClass() . "::DATABASE_NAME);
if (\$values instanceof Criteria) {
\$criteria = clone \$values; // rename for clarity
@@ -1464,7 +1432,7 @@ public static function doUpdate(\$values, ConnectionInterface \$con = null)
if (\$value) {
\$selectCriteria->add(".$this->getColumnConstant($col).", \$value, \$comparison);
} else {
- \$selectCriteria->setPrimaryTableName(static::TABLE_NAME);
+ \$selectCriteria->setPrimaryTableName(" . $this->getTableMapClass() . "::TABLE_NAME);
}
";
} /* if col is prim key */
@@ -1477,7 +1445,7 @@ public static function doUpdate(\$values, ConnectionInterface \$con = null)
}
// set the correct dbName
- \$criteria->setDbName(self::DATABASE_NAME);
+ \$criteria->setDbName(" . $this->getTableMapClass() . "::DATABASE_NAME);
return {$this->basePeerClassName}::doUpdate(\$selectCriteria, \$criteria, \$con);
}
@@ -1501,7 +1469,7 @@ protected function addDoDeleteAll(&$script)
public static function doDeleteAll(ConnectionInterface \$con = null)
{
if (null === \$con) {
- \$con = Propel::getServiceContainer()->getWriteConnection(static::DATABASE_NAME);
+ \$con = Propel::getServiceContainer()->getWriteConnection(" . $this->getTableMapClass() . "::DATABASE_NAME);
}
\$affectedRows = 0; // initialize var to track total num of affected rows
try {
@@ -1510,26 +1478,27 @@ public static function doDeleteAll(ConnectionInterface \$con = null)
\$con->beginTransaction();
";
if ($this->isDeleteCascadeEmulationNeeded()) {
- $script .="\$affectedRows += static::doOnDeleteCascade(new Criteria(static::DATABASE_NAME), \$con);
+ $script .="\$affectedRows += static::doOnDeleteCascade(new Criteria(" . $this->getTableMapClass() . "::DATABASE_NAME), \$con);
";
}
if ($this->isDeleteSetNullEmulationNeeded()) {
- $script .= "static::doOnDeleteSetNull(new Criteria(static::DATABASE_NAME), \$con);
+ $script .= "static::doOnDeleteSetNull(new Criteria(" . $this->getTableMapClass() . "::DATABASE_NAME), \$con);
";
}
- $script .= "\$affectedRows += {$this->basePeerClassName}::doDeleteAll(static::TABLE_NAME, \$con, static::DATABASE_NAME);
+ $script .= "\$affectedRows += {$this->basePeerClassName}::doDeleteAll(" . $this->getTableMapClass() . "::TABLE_NAME, \$con, " . $this->getTableMapClass() . "::DATABASE_NAME);
// Because this db requires some delete cascade/set null emulation, we have to
// clear the cached instance *after* the emulation has happened (since
// instances get re-added by the select statement contained therein).
static::clearInstancePool();
static::clearRelatedInstancePool();
- \$con->commit();
- return \$affectedRows;
+ \$con->commit();
} catch (PropelException \$e) {
\$con->rollBack();
throw \$e;
}
+
+ return \$affectedRows;
}
";
}
@@ -1557,7 +1526,7 @@ protected function addDoDelete(&$script)
static public function doDelete(\$values, ConnectionInterface \$con = null)
{
if (null === \$con) {
- \$con = Propel::getServiceContainer()->getWriteConnection(static::DATABASE_NAME);
+ \$con = Propel::getServiceContainer()->getWriteConnection(" . $this->getTableMapClass() . "::DATABASE_NAME);
}
if (\$values instanceof Criteria) {";
@@ -1590,7 +1559,7 @@ static public function doDelete(\$values, ConnectionInterface \$con = null)
$script .= "
} else { // it's a primary key, or an array of pks";
$script .= "
- \$criteria = new Criteria(self::DATABASE_NAME);";
+ \$criteria = new Criteria(" . $this->getTableMapClass() . "::DATABASE_NAME);";
if (1 === count($table->getPrimaryKey())) {
$pkey = $table->getPrimaryKey();
@@ -1639,7 +1608,7 @@ static public function doDelete(\$values, ConnectionInterface \$con = null)
}
// Set the correct dbName
- \$criteria->setDbName(self::DATABASE_NAME);
+ \$criteria->setDbName(" . $this->getTableMapClass() . "::DATABASE_NAME);
\$affectedRows = 0; // initialize var to track total num of affected rows
@@ -1750,7 +1719,7 @@ protected static function doOnDeleteCascade(Criteria \$criteria, ConnectionInter
$script .= "
// delete related $fkClassName objects
- \$criteria = new Criteria(".$joinedTablePeerBuilder->getPeerClassName(true)."::DATABASE_NAME);
+ \$criteria = new Criteria(".$joinedTablePeerBuilder->getTableMapClass()."::DATABASE_NAME);
";
for ($x = 0, $xlen = count($columnNamesF); $x < $xlen; $x++) {
$columnFK = $tblFK->getColumn($columnNamesF[$x]);
@@ -1827,8 +1796,8 @@ protected static function doOnDeleteSetNull(Criteria \$criteria, ConnectionInter
$columnNamesL = $fk->getForeignColumns(); // should be same num as foreign
$script .= "
// set fkey col in related $fkClassName rows to NULL
- \$selectCriteria = new Criteria(static::DATABASE_NAME);
- \$updateValues = new Criteria(static::DATABASE_NAME);";
+ \$selectCriteria = new Criteria(" . $this->getTableMapClass() . "::DATABASE_NAME);
+ \$updateValues = new Criteria(" . $this->getTableMapClass() . "::DATABASE_NAME);";
for ($x = 0, $xlen = count($columnNamesF); $x < $xlen; $x++) {
$columnFK = $tblFK->getColumn($columnNamesF[$x]);
@@ -1878,10 +1847,10 @@ static public function ".$this->getRetrieveMethodName()."(\$pk, ConnectionInterf
}
if (null === \$con) {
- \$con = Propel::getServiceContainer()->getReadConnection(static::DATABASE_NAME);
+ \$con = Propel::getServiceContainer()->getReadConnection(" . $this->getTableMapClass() . "::DATABASE_NAME);
}
- \$criteria = new Criteria(static::DATABASE_NAME);
+ \$criteria = new Criteria(" . $this->getTableMapClass() . "::DATABASE_NAME);
\$criteria->add(".$this->getColumnConstant($col).", \$pk);
\$v = static::doSelect(\$criteria, \$con);
@@ -1910,14 +1879,14 @@ protected function addRetrieveByPKs_SinglePK(&$script)
static public function ".$this->getRetrieveMethodName()."s(\$pks, ConnectionInterface \$con = null)
{
if (null === \$con) {
- \$con = Propel::getServiceContainer()->getReadConnection(static::DATABASE_NAME);
+ \$con = Propel::getServiceContainer()->getReadConnection(" . $this->getTableMapClass() . "::DATABASE_NAME);
}
\$objs = null;
if (empty(\$pks)) {
\$objs = array();
} else {
- \$criteria = new Criteria(static::DATABASE_NAME);";
+ \$criteria = new Criteria(" . $this->getTableMapClass() . "::DATABASE_NAME);";
$k1 = $table->getPrimaryKey();
$script .= "
\$criteria->add(".$this->getColumnConstant($k1[0]).", \$pks, Criteria::IN);";
@@ -1968,9 +1937,9 @@ static public function ".$this->getRetrieveMethodName()."(";
}
if (null === \$con) {
- \$con = Propel::getServiceContainer()->getReadConnection(static::DATABASE_NAME);
+ \$con = Propel::getServiceContainer()->getReadConnection(" . $this->getTableMapClass() . "::DATABASE_NAME);
}
- \$criteria = new Criteria(static::DATABASE_NAME);";
+ \$criteria = new Criteria(" . $this->getTableMapClass() . "::DATABASE_NAME);";
foreach ($table->getPrimaryKey() as $col) {
$clo = strtolower($col->getName());
$script .= "
@@ -1999,7 +1968,7 @@ protected function addGetTableMap(&$script)
*/
public static function getTableMap()
{
- return Propel::getServiceContainer()->getDatabaseMap(self::DATABASE_NAME)->getTable(self::TABLE_NAME);
+ return Propel::getServiceContainer()->getDatabaseMap(" . $this->getTableMapClass() . "::DATABASE_NAME)->getTable(" . $this->getTableMapClass() . "::TABLE_NAME);
}
";
}
@@ -2150,11 +2119,11 @@ public static function doSelectJoin".$thisTableObjectBuilder->getFKPhpNameAffix(
// Set the correct dbName if it has not been overridden
if (\$criteria->getDbName() == Propel::getServiceContainer()->getDefaultDatasource()) {
- \$criteria->setDbName(self::DATABASE_NAME);
+ \$criteria->setDbName(" . $this->getTableMapClass() . "::DATABASE_NAME);
}
static::addSelectColumns(\$criteria);
- \$startcol = static::NUM_HYDRATE_COLUMNS;
+ \$startcol = " . $this->getTableMapClass() . "::NUM_HYDRATE_COLUMNS;
".$joinedTablePeerBuilder->getPeerClassName(true)."::addSelectColumns(\$criteria);
";
@@ -2282,7 +2251,7 @@ public static function doCountJoin".$thisTableObjectBuilder->getFKPhpNameAffix($
// We need to set the primary table name, since in the case that there are no WHERE columns
// it will be impossible for the BasePeer::createSelectSql() method to determine which
// tables go into the FROM clause.
- \$criteria->setPrimaryTableName(static::TABLE_NAME);
+ \$criteria->setPrimaryTableName(" . $this->getTableMapClass() . "::TABLE_NAME);
if (\$distinct && !in_array(Criteria::DISTINCT, \$criteria->getSelectModifiers())) {
\$criteria->setDistinct();
@@ -2295,10 +2264,10 @@ public static function doCountJoin".$thisTableObjectBuilder->getFKPhpNameAffix($
\$criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
// Set the correct dbName
- \$criteria->setDbName(self::DATABASE_NAME);
+ \$criteria->setDbName(" . $this->getTableMapClass() . "::DATABASE_NAME);
if (null === \$con) {
- \$con = Propel::getServiceContainer()->getReadConnection(static::DATABASE_NAME);
+ \$con = Propel::getServiceContainer()->getReadConnection(" . $this->getTableMapClass() . "::DATABASE_NAME);
}
";
$script .= $this->addCriteriaJoin($fk, $table, $joinTable, $joinedTablePeerBuilder);
@@ -2353,11 +2322,11 @@ public static function doSelectJoinAll(Criteria \$criteria, \$con = null, \$join
// Set the correct dbName if it has not been overridden
if (\$criteria->getDbName() == Propel::getServiceContainer()->getDefaultDatasource()) {
- \$criteria->setDbName(self::DATABASE_NAME);
+ \$criteria->setDbName(" . $this->getTableMapClass() . "::DATABASE_NAME);
}
static::addSelectColumns(\$criteria);
- \$startcol2 = static::NUM_HYDRATE_COLUMNS;
+ \$startcol2 = " . $this->getTableMapClass() . "::NUM_HYDRATE_COLUMNS;
";
$index = 2;
foreach ($table->getForeignKeys() as $fk) {
@@ -2370,10 +2339,11 @@ public static function doSelectJoinAll(Criteria \$criteria, \$con = null, \$join
$joinedTablePeerBuilder = $this->getNewPeerBuilder($joinTable);
$joinClassName = $joinedTablePeerBuilder->getObjectClassName();
+ $this->declareClass($joinedTablePeerBuilder->getTableMapBuilder()->getFullyQualifiedClassName());
$script .= "
".$joinedTablePeerBuilder->getPeerClassName(true)."::addSelectColumns(\$criteria);
- \$startcol$new_index = \$startcol$index + ".$joinedTablePeerBuilder->getPeerClassName(true)."::NUM_HYDRATE_COLUMNS;
+ \$startcol$new_index = \$startcol$index + ".$joinedTablePeerBuilder->getTableMapClass()."::NUM_HYDRATE_COLUMNS;
";
$index = $new_index;
@@ -2521,7 +2491,7 @@ public static function doCountJoinAll(Criteria \$criteria, \$distinct = false, C
// We need to set the primary table name, since in the case that there are no WHERE columns
// it will be impossible for the BasePeer::createSelectSql() method to determine which
// tables go into the FROM clause.
- \$criteria->setPrimaryTableName(static::TABLE_NAME);
+ \$criteria->setPrimaryTableName(" . $this->getTableMapClass() . "::TABLE_NAME);
if (\$distinct && !in_array(Criteria::DISTINCT, \$criteria->getSelectModifiers())) {
\$criteria->setDistinct();
@@ -2534,10 +2504,10 @@ public static function doCountJoinAll(Criteria \$criteria, \$distinct = false, C
\$criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
// Set the correct dbName
- \$criteria->setDbName(self::DATABASE_NAME);
+ \$criteria->setDbName(" . $this->getTableMapClass() . "::DATABASE_NAME);
if (null === \$con) {
- \$con = Propel::getServiceContainer()->getReadConnection(static::DATABASE_NAME);
+ \$con = Propel::getServiceContainer()->getReadConnection(" . $this->getTableMapClass() . "::DATABASE_NAME);
}
";
@@ -2613,11 +2583,11 @@ public static function doSelectJoinAllExcept".$thisTableObjectBuilder->getFKPhpN
// \$criteria->getDbName() will return the same object if not set to another value
// so == check is okay and faster
if (\$criteria->getDbName() == Propel::getServiceContainer()->getDefaultDatasource()) {
- \$criteria->setDbName(self::DATABASE_NAME);
+ \$criteria->setDbName(" . $this->getTableMapClass() . "::DATABASE_NAME);
}
static::addSelectColumns(\$criteria);
- \$startcol2 = static::NUM_HYDRATE_COLUMNS;
+ \$startcol2 = " . $this->getTableMapClass() . "::NUM_HYDRATE_COLUMNS;
";
$index = 2;
foreach ($table->getForeignKeys() as $subfk) {
@@ -2632,7 +2602,7 @@ public static function doSelectJoinAllExcept".$thisTableObjectBuilder->getFKPhpN
$new_index = $index + 1;
$script .= "
".$joinTablePeerBuilder->getPeerClassName(true)."::addSelectColumns(\$criteria);
- \$startcol$new_index = \$startcol$index + ".$joinTablePeerBuilder->getPeerClassName(true)."::NUM_HYDRATE_COLUMNS;
+ \$startcol$new_index = \$startcol$index + ".$joinTablePeerBuilder->getTableMapClass()."::NUM_HYDRATE_COLUMNS;
";
$index = $new_index;
} // if joinClassName not excludeClassName
@@ -2792,7 +2762,7 @@ public static function doCountJoinAllExcept".$thisTableObjectBuilder->getFKPhpNa
// We need to set the primary table name, since in the case that there are no WHERE columns
// it will be impossible for the BasePeer::createSelectSql() method to determine which
// tables go into the FROM clause.
- \$criteria->setPrimaryTableName(static::TABLE_NAME);
+ \$criteria->setPrimaryTableName(" . $this->getTableMapClass() . "::TABLE_NAME);
if (\$distinct && !in_array(Criteria::DISTINCT, \$criteria->getSelectModifiers())) {
\$criteria->setDistinct();
@@ -2805,10 +2775,10 @@ public static function doCountJoinAllExcept".$thisTableObjectBuilder->getFKPhpNa
\$criteria->clearOrderByColumns(); // ORDER BY should not affect count
// Set the correct dbName
- \$criteria->setDbName(self::DATABASE_NAME);
+ \$criteria->setDbName(" . $this->getTableMapClass() . "::DATABASE_NAME);
if (null === \$con) {
- \$con = Propel::getServiceContainer()->getReadConnection(static::DATABASE_NAME);
+ \$con = Propel::getServiceContainer()->getReadConnection(" . $this->getTableMapClass() . "::DATABASE_NAME);
}
";
View
3 src/Propel/Generator/Builder/Om/QueryBuilder.php
@@ -171,6 +171,7 @@ protected function addClassBody(&$script)
);
$this->declareClassFromBuilder($this->getStubQueryBuilder(), 'Child');
$this->declareClassFromBuilder($this->getStubPeerBuilder());
+ $this->declareClassFromBuilder($this->getTableMapBuilder());
// apply behaviors
$this->applyBehaviorModifier('queryAttributes', $script, " ");
@@ -415,7 +416,7 @@ public function findPk(\$key, \$con = null)
return \$obj;
}
if (\$con === null) {
- \$con = Propel::getServiceContainer()->getReadConnection({$peerClassName}::DATABASE_NAME);
+ \$con = Propel::getServiceContainer()->getReadConnection({$this->getTableMapClass()}::DATABASE_NAME);
}
\$this->basePreSelect(\$con);
if (\$this->formatter || \$this->modelAlias || \$this->with || \$this->select
View
26 src/Propel/Generator/Builder/Om/TableMapBuilder.php
@@ -97,7 +97,9 @@ protected function addClassBody(&$script)
'\Propel\Runtime\Map\TableMap',
'\Propel\Runtime\Map\RelationMap'
);
- $this->addConstants($script);
+
+ $script .= $this->addConstants();
+
$this->addAttributes($script);
$this->addInitialize($script);
$this->addBuildRelations($script);
@@ -106,16 +108,22 @@ protected function addClassBody(&$script)
/**
* Adds any constants needed for this TableMap class.
- * @param string &$script The script will be modified in this method.
+ *
+ * @return string
*/
- protected function addConstants(&$script)
+ protected function addConstants()
{
- $script .= "
- /**
- * The (dot-path) name of this class
- */
- const CLASS_NAME = '".$this->getClasspath()."';
-";
+ return $this->renderTemplate('tableMapConstants', array(
+ 'className' => $this->getClasspath(),
+ 'dbName' => $this->getDatabase()->getName(),
+ 'tableName' => $this->getTable()->getName(),
+ 'tablePhpName' => $this->getTable()->isAbstract() ? '' : addslashes($this->getStubObjectBuilder()->getFullyQualifiedClassName()),
+ 'classPath' => $this->getStubObjectBuilder()->getClasspath(),
+ 'nbColumns' => $this->getTable()->getNumColumns(),
+ 'nbLazyLoadColumns' => $this->getTable()->getNumLazyLoadColumns(),
+ 'nbHydrateColumns' => $this->getTable()->getNumColumns() - $this->getTable()->getNumLazyLoadColumns(),
+ 'peerClassName' => $this->getStubPeerBuilder()->getFullyQualifiedClassName(),
+ ));
}
/**
View
6 src/Propel/Generator/Builder/Om/templates/baseObjectMethods.php
@@ -12,7 +12,7 @@ public function isModified()
/**
* Has specified column been modified?
*
- * @param string $col column fully qualified name (BasePeer::TYPE_COLNAME), e.g. Book::AUTHOR_ID
+ * @param string $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID
* @return boolean True if $col has been modified.
*/
public function isColumnModified($col)
@@ -212,7 +212,7 @@ public function importFrom($parser, $data)
$parser = AbstractParser::getParser($parser);
}
- return $this->fromArray($parser->toArray($data), BasePeer::TYPE_PHPNAME);
+ return $this->fromArray($parser->toArray($data), TableMap::TYPE_PHPNAME);
}
/**
@@ -233,7 +233,7 @@ public function exportTo($parser, $includeLazyLoadColumns = true)
$parser = AbstractParser::getParser($parser);
}
- return $parser->fromArray($this->toArray(BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true));
+ return $parser->fromArray($this->toArray(TableMap::TYPE_PHPNAME, $includeLazyLoadColumns, array(), true));
}
/**
View
44 src/Propel/Generator/Builder/Om/templates/tableMapConstants.php
@@ -0,0 +1,44 @@
+ /**
+ * The (dot-path) name of this class
+ */
+ const CLASS_NAME = '<?php echo $className ?>';
+
+ /**
+ * The default database name for this class
+ */
+ const DATABASE_NAME = '<?php echo $dbName ?>';
+
+ /**
+ * The table name for this class
+ */
+ const TABLE_NAME = '<?php echo $tableName ?>';
+
+ /**
+ * The related Propel class for this table
+ */
+ const OM_CLASS = '<?php echo $tablePhpName ?>';
+
+ /**
+ * A class that can be returned by this peer
+ */
+ const CLASS_DEFAULT = '<?php echo $classPath ?>';
+
+ /**
+ * The related TableMap class for this table
+ */
+ const PEER_CLASS = '<?php echo $peerClassName ?>';
+
+ /**
+ * The total number of columns
+ */
+ const NUM_COLUMNS = <?php echo $nbColumns ?>;
+
+ /**
+ * The number of lazy-loaded columns
+ */
+ const NUM_LAZY_LOAD_COLUMNS = <?php echo $nbLazyLoadColumns ?>;
+
+ /**
+ * The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS)
+ */
+ const NUM_HYDRATE_COLUMNS = <?php echo $nbHydrateColumns ?>;
View
20 src/Propel/Runtime/ActiveQuery/ModelCriteria.php
@@ -64,6 +64,8 @@ class ModelCriteria extends Criteria implements \IteratorAggregate
protected $modelPeerName;
+ protected $modelTableMapName;
+
protected $modelAlias;
protected $useAliasInSQL = false;
@@ -104,15 +106,17 @@ public function __construct($dbName = null, $modelName = null, $modelAlias = nul
{
$this->setDbName($dbName);
$this->originalDbName = $dbName;
+
if (0 === strpos($modelName, '\\')) {
$this->modelName = substr($modelName, 1);
} else {
$this->modelName = $modelName;
}
- $this->modelPeerName = constant($this->modelName . '::PEER');
- $this->modelAlias = $modelAlias;
- $this->tableMap = Propel::getServiceContainer()->getDatabaseMap($this->getDbName())->getTableByPhpName($this->modelName);
+ $this->modelTableMapName = constant($this->modelName . '::TABLE_MAP');
+ $this->modelPeerName = constant($this->modelTableMapName . '::PEER_CLASS');
+ $this->modelAlias = $modelAlias;
+ $this->tableMap = Propel::getServiceContainer()->getDatabaseMap($this->getDbName())->getTableByPhpName($this->modelName);
}
/**
@@ -546,7 +550,7 @@ public function select($columnArray)
if ('*' === $columnArray) {
$columnArray = array();
- foreach (call_user_func(array($this->modelPeerName, 'getFieldNames'), BasePeer::TYPE_PHPNAME) as $column) {
+ foreach (call_user_func(array($this->modelPeerName, 'getFieldNames'), TableMap::TYPE_PHPNAME) as $column) {
$columnArray []= $this->modelName . '.' . $column;
}
}
@@ -586,7 +590,7 @@ protected function configureSelectColumns()
// it will be impossible for the BasePeer::createSelectSql() method to determine which
// tables go into the FROM clause.
if (!$this->selectQueries) {
- $this->setPrimaryTableName(constant($this->modelPeerName . '::TABLE_NAME'));
+ $this->setPrimaryTableName(constant($this->modelTableMapName . '::TABLE_NAME'));
}
// Add requested columns which are not withColumns
@@ -1246,7 +1250,7 @@ public function findOneOrCreate($con = null)
$class = $this->getModelName();
$obj = new $class();
foreach ($this->keys() as $key) {
- $obj->setByName($key, $this->getValue($key), BasePeer::TYPE_COLNAME);
+ $obj->setByName($key, $this->getValue($key), TableMap::TYPE_COLNAME);
}
$ret = $this->getFormatter()->formatRecord($obj);
}
@@ -1496,7 +1500,7 @@ public function count($con = null)
// We need to set the primary table name, since in the case that there are no WHERE columns
// it will be impossible for the BasePeer::createSelectSql() method to determine which
// tables go into the FROM clause.
- $criteria->setPrimaryTableName(constant($this->modelPeerName.'::TABLE_NAME'));
+ $criteria->setPrimaryTableName(constant($this->modelTableMapName . '::TABLE_NAME'));
$stmt = $criteria->doCount($con);
if ($row = $stmt->fetch(\PDO::FETCH_NUM)) {
@@ -1759,7 +1763,7 @@ public function update($values, $con = null, $forceIndividualSaves = false)
}
$criteria = $this->isKeepQuery() ? clone $this : $this;
- $criteria->setPrimaryTableName(constant($this->modelPeerName.'::TABLE_NAME'));
+ $criteria->setPrimaryTableName(constant($this->modelTableMapName.'::TABLE_NAME'));
$con->beginTransaction();
try {
View
2 src/Propel/Runtime/Adapter/Pdo/OracleAdapter.php
@@ -10,13 +10,13 @@
namespace Propel\Runtime\Adapter\Pdo;
+use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\Adapter\AdapterInterface;
use Propel\Runtime\Connection\ConnectionInterface;
use Propel\Runtime\Connection\StatementInterface;
use Propel\Runtime\Exception\InvalidArgumentException;
use Propel\Runtime\Map\ColumnMap;
use Propel\Runtime\Util\BasePeer;
-use Propel\Runtime\ActiveQuery\Criteria;
/**
* Oracle adapter.
View
4 src/Propel/Runtime/Adapter/Pdo/PgsqlAdapter.php
@@ -18,9 +18,7 @@
use Propel\Runtime\Util\BasePeer;
/**
- * This is used to connect to PostgresQL databases.
- *
- * <a href="http://www.pgsql.org">http://www.pgsql.org</a>
+ * This is used to connect to PostgreSQL databases.
*
* @author Hans Lellelid <hans@xmpl.org> (Propel)
* @author Hakan Tandogan <hakan42@gmx.de> (Torque)
View
19 src/Propel/Runtime/Collection/Collection.php
@@ -18,7 +18,7 @@
use Propel\Runtime\Exception\UnexpectedValueException;
use Propel\Runtime\Formatter\AbstractFormatter;
use Propel\Runtime\Parser\AbstractParser;
-use Propel\Runtime\Util\BasePeer;
+use Propel\Runtime\Map\TableMap;
/**
* Class for iterating over a list of Propel elements
@@ -484,6 +484,17 @@ public function getPeerClass()
return constant($this->getFullyQualifiedModel() . '::PEER');
}
+ public function getTableMapClass()
+ {
+ $model = $this->getModel();
+
+ if (empty($model)) {
+ throw new ModelNotFoundException('You must set the collection model before interacting with it');
+ }
+
+ return constant($this->getFullyQualifiedModel() . '::TABLE_MAP');
+ }
+
/**
* @param AbstractFormatter $formatter
*/
@@ -507,7 +518,7 @@ public function getFormatter()
*/
public function getWriteConnection()
{
- $databaseName = constant($this->getPeerClass() . '::DATABASE_NAME');
+ $databaseName = constant($this->getTableMapClass() . '::DATABASE_NAME');
return Propel::getServiceContainer()->getWriteConnection($databaseName);
}
@@ -531,7 +542,7 @@ public function importFrom($parser, $data)
$parser = AbstractParser::getParser($parser);
}
- return $this->fromArray($parser->listToArray($data), BasePeer::TYPE_PHPNAME);
+ return $this->fromArray($parser->listToArray($data), TableMap::TYPE_PHPNAME);
}
/**
@@ -560,7 +571,7 @@ public function exportTo($parser, $usePrefix = true, $includeLazyLoadColumns = t
$parser = AbstractParser::getParser($parser);
}
- return $parser->listFromArray($this->toArray(null, $usePrefix, BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns));
+ return $parser->listFromArray($this->toArray(null, $usePrefix, TableMap::TYPE_PHPNAME, $includeLazyLoadColumns));
}
/**
View
10 src/Propel/Runtime/Collection/ObjectCollection.php
@@ -17,8 +17,8 @@
use Propel\Runtime\Exception\PropelException;
use Propel\Runtime\Exception\RuntimeException;
use Propel\Runtime\Map\RelationMap;
+use Propel\Runtime\Map\TableMap;
use Propel\Runtime\ActiveQuery\PropelQuery;
-use Propel\Runtime\Util\BasePeer;
/**
* Class for iterating over a list of Propel objects
@@ -124,9 +124,9 @@ public function fromArray($arr)
* Otherwise, the array is indexed using the specified column
* @param boolean $usePrefix If true, the returned array prefixes keys
* with the model class name ('Article_0', 'Article_1', etc).
- * @param string $keyType (optional) One of the class type constants BasePeer::TYPE_PHPNAME,
- * BasePeer::TYPE_STUDLYPHPNAME, BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME,
- * BasePeer::TYPE_NUM. Defaults to BasePeer::TYPE_PHPNAME.
+ * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME,
+ * TableMap::TYPE_STUDLYPHPNAME, TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME,
+ * TableMap::TYPE_NUM. Defaults to TableMap::TYPE_PHPNAME.
* @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE.
* @param array $alreadyDumpedObjects List of objects to skip to avoid recursion
*
@@ -150,7 +150,7 @@ public function fromArray($arr)
*
* @return array
*/
- public function toArray($keyColumn = null, $usePrefix = false, $keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array())
+ public function toArray($keyColumn = null, $usePrefix = false, $keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array())
{
$ret = array();
$keyGetterMethod = 'get' . $keyColumn;
View
10 src/Propel/Runtime/Collection/OnDemandCollection.php
@@ -14,7 +14,7 @@
use Propel\Runtime\Connection\StatementInterface;
use Propel\Runtime\Exception\PropelException;
use Propel\Runtime\Formatter\AbstractFormatter;
-use Propel\Runtime\Util\BasePeer;
+use Propel\Runtime\Map\TableMap;
/**
* Class for iterating over a statement and returning one Propel object at a time
@@ -52,9 +52,9 @@ public function initIterator(AbstractFormatter $formatter, StatementInterface $s
* Otherwise, the array is indexed using the specified column
* @param boolean $usePrefix If true, the returned array prefixes keys
* with the model class name ('Article_0', 'Article_1', etc).
- * @param string $keyType (optional) One of the class type constants BasePeer::TYPE_PHPNAME,
- * BasePeer::TYPE_STUDLYPHPNAME, BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME,
- * BasePeer::TYPE_NUM. Defaults to BasePeer::TYPE_PHPNAME.
+ * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME,
+ * TableMap::TYPE_STUDLYPHPNAME, TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME,
+ * TableMap::TYPE_NUM. Defaults to TableMap::TYPE_PHPNAME.
* @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE.
* @param array $alreadyDumpedObjects List of objects to skip to avoid recursion
*
@@ -78,7 +78,7 @@ public function initIterator(AbstractFormatter $formatter, StatementInterface $s
*
* @return array
*/
- public function toArray($keyColumn = null, $usePrefix = false, $keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array())
+ public function toArray($keyColumn = null, $usePrefix = false, $keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array())
{
$ret = array();
$keyGetterMethod = 'get' . $keyColumn;
View
46 src/Propel/Runtime/Map/TableMap.php
@@ -16,20 +16,50 @@
/**
* TableMap is used to model a table in a database.
*
- * GENERAL NOTE
- * ------------
- * The propel.map classes are abstract building-block classes for modeling
- * the database at runtime. These classes are similar (a lite version) to the
- * propel.engine.database.model classes, which are build-time modeling classes.
- * These classes in themselves do not do any database metadata lookups.
- *
* @author Hans Lellelid <hans@xmpl.org> (Propel)
* @author John D. McNally <jmcnally@collab.net> (Torque)
* @author Daniel Rall <dlr@finemaltcoding.com> (Torque)
+ * @author William Durand <william.durand1@gmail.com>
*/
class TableMap
{
/**
+ * phpname type
+ * e.g. 'AuthorId'
+ */
+ const TYPE_PHPNAME = 'phpName';
+
+ /**
+ * studlyphpname type
+ * e.g. 'authorId'
+ */
+ const TYPE_STUDLYPHPNAME = 'studlyPhpName';
+
+ /**
+ * column (peer) name type
+ * e.g. 'book.AUTHOR_ID'
+ */
+ const TYPE_COLNAME = 'colName';
+
+ /**
+ * column part of the column peer name
+ * e.g. 'AUTHOR_ID'
+ */
+ const TYPE_RAW_COLNAME = 'rawColName';
+
+ /**
+ * column fieldname type
+ * e.g. 'author_id'
+ */
+ const TYPE_FIELDNAME = 'fieldName';
+
+ /**
+ * num type
+ * simply the numerical array index, e.g. 4
+ */
+ const TYPE_NUM = 'num';
+
+ /**
* Columns in the table
*
* @var ColumnMap[]
@@ -671,5 +701,7 @@ public function getPrimaryStringColumn()
return $column;
}
}
+
+ return null;
}
}
View
43 src/Propel/Runtime/Util/BasePeer.php
@@ -14,6 +14,7 @@
use Propel\Runtime\Exception\RuntimeException;
use Propel\Runtime\Propel;
use Propel\Runtime\ActiveQuery\Criteria;
+use Propel\Runtime\Map\TableMap;
/**
* This is a utility class for all generated Peer classes in the system.
@@ -39,43 +40,7 @@ class BasePeer
*/
private static $mapBuilders = array();
- /**
- * phpname type
- * e.g. 'AuthorId'
- */
- const TYPE_PHPNAME = 'phpName';
-
- /**
- * studlyphpname type
- * e.g. 'authorId'
- */
- const TYPE_STUDLYPHPNAME = 'studlyPhpName';
-
- /**
- * column (peer) name type
- * e.g. 'book.AUTHOR_ID'
- */
- const TYPE_COLNAME = 'colName';
-
- /**
- * column part of the column peer name
- * e.g. 'AUTHOR_ID'
- */
- const TYPE_RAW_COLNAME = 'rawColName';
-
- /**
- * column fieldname type
- * e.g. 'author_id'
- */
- const TYPE_FIELDNAME = 'fieldName';
-
- /**
- * num type
- * simply the numerical array index, e.g. 4
- */
- const TYPE_NUM = 'num';
-
- public static function getFieldnames($classname, $type = self::TYPE_PHPNAME)
+ public static function getFieldnames($classname, $type = TableMap::TYPE_PHPNAME)
{
$peerclass = $classname . 'Peer';
$callable = array($peerclass, 'getFieldnames');
@@ -158,8 +123,8 @@ public static function doDelete(Criteria $criteria, ConnectionInterface $con)
* <code>
* static public function doDeleteAll($con = null)
* {
- * if ($con === null) $con = Propel::getServiceContainer()->getWriteConnection(self::DATABASE_NAME);
- * BasePeer::doDeleteAll(self::TABLE_NAME, $con, self::DATABASE_NAME);
+ * if ($con === null) $con = Propel::getServiceContainer()->getWriteConnection(TableMap::DATABASE_NAME);
+ * BasePeer::doDeleteAll(TableMap::TABLE_NAME, $con, TableMap::DATABASE_NAME);
* }
* </code>
*
View
4 src/Propel/Runtime/Validator/Constraints/UniqueValidator.php
@@ -10,9 +10,9 @@
namespace Propel\Runtime\Validator\Constraints;
+use Propel\Runtime\Map\TableMap;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
-use Propel\Runtime\Util\BasePeer;
class UniqueValidator extends ConstraintValidator
{
@@ -26,7 +26,7 @@ public function isValid($value, Constraint $constraint)
$peer = $object->getPeer();
$className = get_class($object);
$queryClass = $className . 'Query';
- $filter = sprintf('filterBy%s', $peer->translateFieldName($this->context->getCurrentProperty(), BasePeer::TYPE_STUDLYPHPNAME, BasePeer::TYPE_PHPNAME));
+ $filter = sprintf('filterBy%s', $peer->translateFieldName($this->context->getCurrentProperty(), TableMap::TYPE_STUDLYPHPNAME, TableMap::TYPE_PHPNAME));
if (0 < $queryClass::create()->$filter($value)->count()) {
$this->setMessage($constraint->message);
View
142 tests/Propel/Tests/FieldnameRelatedTest.php
@@ -10,8 +10,8 @@
namespace Propel\Tests;
+use Propel\Runtime\Map\TableMap;
use Propel\Runtime\Util\BasePeer;
-
use Propel\Tests\Bookstore\Book;
use Propel\Tests\Bookstore\BookPeer;
use Propel\Tests\Bookstore\Bookstore;
@@ -41,7 +41,7 @@ class FieldnameRelatedTest extends \PHPUnit_Framework_TestCase
*/
public function testFieldNameTypeConstants ()
{
- $result = defined('\Propel\Runtime\Util\BasePeer::TYPE_PHPNAME');
+ $result = defined('\Propel\Runtime\Map\TableMap::TYPE_PHPNAME');
$this->assertTrue($result);
}
@@ -51,45 +51,45 @@ public function testFieldNameTypeConstants ()
public function testGetFieldNames ()
{
$types = array(
- BasePeer::TYPE_PHPNAME,
- BasePeer::TYPE_COLNAME,
- BasePeer::TYPE_FIELDNAME,
- BasePeer::TYPE_NUM
+ TableMap::TYPE_PHPNAME,
+ TableMap::TYPE_COLNAME,
+ TableMap::TYPE_FIELDNAME,
+ TableMap::TYPE_NUM
);
$expecteds = array (
- BasePeer::TYPE_PHPNAME => array(
+ TableMap::TYPE_PHPNAME => array(
0 => 'Id',
1 => 'Title',
2 => 'ISBN',
3 => 'Price',
4 => 'PublisherId',
5 => 'AuthorId'
),
- BasePeer::TYPE_STUDLYPHPNAME => array(
+ TableMap::TYPE_STUDLYPHPNAME => array(
0 => 'id',
1 => 'title',
2 => 'iSBN',
3 => 'price',
4 => 'publisherId',
5 => 'authorId'
),
- BasePeer::TYPE_COLNAME => array(
+ TableMap::TYPE_COLNAME => array(
0 => 'book.ID',
1 => 'book.TITLE',
2 => 'book.ISBN',
3 => 'book.PRICE',
4 => 'book.PUBLISHER_ID',
5 => 'book.AUTHOR_ID'
),
- BasePeer::TYPE_FIELDNAME => array(
+ TableMap::TYPE_FIELDNAME => array(
0 => 'id',
1 => 'title',
2 => 'isbn',
3 => 'price',
4 => 'publisher_id',
5 => 'author_id'
),
- BasePeer::TYPE_NUM => array(
+ TableMap::TYPE_NUM => array(
0 => 0,
1 => 1,
2 => 2,
@@ -116,18 +116,18 @@ public function testGetFieldNames ()
public function testTranslateFieldName ()
{
$types = array(
- BasePeer::TYPE_PHPNAME,
- BasePeer::TYPE_STUDLYPHPNAME,
- BasePeer::TYPE_COLNAME,
- BasePeer::TYPE_FIELDNAME,
- BasePeer::TYPE_NUM
+ TableMap::TYPE_PHPNAME,
+ TableMap::TYPE_STUDLYPHPNAME,
+ TableMap::TYPE_COLNAME,
+ TableMap::TYPE_FIELDNAME,
+ TableMap::TYPE_NUM
);
$expecteds = array (
- BasePeer::TYPE_PHPNAME => 'AuthorId',
- BasePeer::TYPE_STUDLYPHPNAME => 'authorId',
- BasePeer::TYPE_COLNAME => 'book.AUTHOR_ID',
- BasePeer::TYPE_FIELDNAME => 'author_id',
- BasePeer::TYPE_NUM => 5,
+ TableMap::TYPE_PHPNAME => 'AuthorId',
+ TableMap::TYPE_STUDLYPHPNAME => 'authorId',
+ TableMap::TYPE_COLNAME => 'book.AUTHOR_ID',
+ TableMap::TYPE_FIELDNAME => 'author_id',
+ TableMap::TYPE_NUM => 5,
);
foreach ($types as $fromType) {
foreach ($types as $toType) {
@@ -145,46 +145,46 @@ public function testTranslateFieldName ()
public function testGetFieldNamesStatic ()
{
$types = array(
- BasePeer::TYPE_PHPNAME,
- BasePeer::TYPE_STUDLYPHPNAME,
- BasePeer::TYPE_COLNAME,
- BasePeer::TYPE_FIELDNAME,
- BasePeer::TYPE_NUM
+ TableMap::TYPE_PHPNAME,
+ TableMap::TYPE_STUDLYPHPNAME,
+ TableMap::TYPE_COLNAME,
+ TableMap::TYPE_FIELDNAME,
+ TableMap::TYPE_NUM
);
$expecteds = array (
- BasePeer::TYPE_PHPNAME => array(
+ TableMap::TYPE_PHPNAME => array(
0 => 'Id',
1 => 'Title',
2 => 'ISBN',
3 => 'Price',
4 => 'PublisherId',
5 => 'AuthorId'
),
- BasePeer::TYPE_STUDLYPHPNAME => array(
+ TableMap::TYPE_STUDLYPHPNAME => array(
0 => 'id',
1 => 'title',
2 => 'iSBN',
3 => 'price',
4 => 'publisherId',
5 => 'authorId'
),
- BasePeer::TYPE_COLNAME => array(
+ TableMap::TYPE_COLNAME => array(
0 => 'book.ID',
1 => 'book.TITLE',
2 => 'book.ISBN',
3 => 'book.PRICE',
4 => 'book.PUBLISHER_ID',
5 => 'book.AUTHOR_ID'
),
- BasePeer::TYPE_FIELDNAME => array(
+ TableMap::TYPE_FIELDNAME => array(
0 => 'id',
1 => 'title',
2 => 'isbn',
3 => 'price',
4 => 'publisher_id',
5 => 'author_id'
),
- BasePeer::TYPE_NUM => array(
+ TableMap::TYPE_NUM => array(
0 => 0,
1 => 1,
2 => 2,
@@ -211,18 +211,18 @@ public function testGetFieldNamesStatic ()
public function testTranslateFieldNameStatic ()
{
$types = array(
- BasePeer::TYPE_PHPNAME,
- BasePeer::TYPE_STUDLYPHPNAME,
- BasePeer::TYPE_COLNAME,
- BasePeer::TYPE_FIELDNAME,
- BasePeer::TYPE_NUM
+ TableMap::TYPE_PHPNAME,
+ TableMap::TYPE_STUDLYPHPNAME,
+ TableMap::TYPE_COLNAME,
+ TableMap::TYPE_FIELDNAME,
+ TableMap::TYPE_NUM
);
$expecteds = array (
- BasePeer::TYPE_PHPNAME => 'AuthorId',
- BasePeer::TYPE_STUDLYPHPNAME => 'authorId',
- BasePeer::TYPE_COLNAME => 'book.AUTHOR_ID',
- BasePeer::TYPE_FIELDNAME => 'author_id',
- BasePeer::TYPE_NUM => 5,
+ TableMap::TYPE_PHPNAME => 'AuthorId',
+ TableMap::TYPE_STUDLYPHPNAME => 'authorId',
+ TableMap::TYPE_COLNAME => 'book.AUTHOR_ID',
+ TableMap::TYPE_FIELDNAME => 'author_id',
+ TableMap::TYPE_NUM => 5,
);
foreach ($types as $fromType) {
foreach ($types as $toType) {
@@ -240,11 +240,11 @@ public function testTranslateFieldNameStatic ()
public function testGetByName()
{
$types = array(
- BasePeer::TYPE_PHPNAME => 'Title',
- BasePeer::TYPE_STUDLYPHPNAME => 'title',
- BasePeer::TYPE_COLNAME => 'book.TITLE',
- BasePeer::TYPE_FIELDNAME => 'title',
- BasePeer::TYPE_NUM => 1
+ TableMap::TYPE_PHPNAME => 'Title',
+ TableMap::TYPE_STUDLYPHPNAME => 'title',
+ TableMap::TYPE_COLNAME => 'book.TITLE',
+ TableMap::TYPE_FIELDNAME => 'title',
+ TableMap::TYPE_NUM => 1
);
$book = new Book();
@@ -264,11 +264,11 @@ public function testSetByName()
{
$book = new Book();
$types = array(
- BasePeer::TYPE_PHPNAME => 'Title',
- BasePeer::TYPE_STUDLYPHPNAME => 'title',
- BasePeer::TYPE_COLNAME => 'book.TITLE',
- BasePeer::TYPE_FIELDNAME => 'title',
- BasePeer::TYPE_NUM => 1
+ TableMap::TYPE_PHPNAME => 'Title',
+ TableMap::TYPE_STUDLYPHPNAME => 'title',
+ TableMap::TYPE_COLNAME => 'book.TITLE',
+ TableMap::TYPE_FIELDNAME => 'title',
+ TableMap::TYPE_NUM => 1
);
$title = 'Harry Potter and the Order of the Phoenix';
@@ -287,30 +287,30 @@ public function testSetByName()
public function testFromArray()
{
$types = array(
- BasePeer::TYPE_PHPNAME,
- BasePeer::TYPE_STUDLYPHPNAME,
- BasePeer::TYPE_COLNAME,
- BasePeer::TYPE_FIELDNAME,
- BasePeer::TYPE_NUM
+ TableMap::TYPE_PHPNAME,
+ TableMap::TYPE_STUDLYPHPNAME,
+ TableMap::TYPE_COLNAME,
+ TableMap::TYPE_FIELDNAME,
+ TableMap::TYPE_NUM
);
$expecteds = array (
- BasePeer::TYPE_PHPNAME => array (
+ TableMap::TYPE_PHPNAME => array (