Skip to content
Browse files

[Generator] move columns contant from Peer to TableMap

  • Loading branch information...
1 parent 7cba874 commit e2e76738a0fd56d0fdada70a8d05af5db56268d9 @jaugustin jaugustin committed Jan 12, 2013
View
9 src/Propel/Generator/Builder/Om/PeerBuilder.php
@@ -198,7 +198,6 @@ public function getTablePhpName()
*/
protected function addConstantsAndAttributes(&$script)
{
- $this->addColumnNameConstants($script);
$this->addInheritanceColumnConstants($script);
if ($this->getTable()->hasEnumColumns()) {
$this->addEnumColumnConstants($script);
@@ -302,7 +301,7 @@ protected function addFieldNamesAttribute(&$script)
$script .= "),
TableMap::TYPE_COLNAME => array (";
foreach ($tableColumns as $col) {
- $script .= $this->getColumnConstant($col, 'self').", ";
+ $script .= $this->getColumnConstant($col, $this->getTableMapClass()).", ";
}
$script .= "),
TableMap::TYPE_RAW_COLNAME => array (";
@@ -353,7 +352,7 @@ protected function addFieldKeysAttribute(&$script)
$script .= "),
TableMap::TYPE_COLNAME => array (";
foreach ($tableColumns as $num => $col) {
- $script .= $this->getColumnConstant($col, 'self')." => $num, ";
+ $script .= $this->getColumnConstant($col, $this->getTableMapClass())." => $num, ";
}
$script .= "),
TableMap::TYPE_RAW_COLNAME => array (";
@@ -387,7 +386,7 @@ protected function addEnumColumnAttributes(&$script)
foreach ($this->getTable()->getColumns() as $col) {
if ($col->isEnumType()) {
$script .= "
- self::" . $this->getColumnName($col) ." => array(
+ {$col->getConstantName()} => array(
";
foreach ($col->getValueSet() as $value) {
$script .= " self::" . $this->getColumnName($col) . '_' . $this->getEnumValueConstant($value) . ",
@@ -606,7 +605,7 @@ public static function addSelectColumns(Criteria \$criteria, \$alias = null)
foreach ($this->getTable()->getColumns() as $col) {
if (!$col->isLazyLoad()) {
$script .= "
- \$criteria->addSelectColumn(static::".$this->getColumnName($col).");";
+ \$criteria->addSelectColumn({$col->getConstantName()});";
} // if !col->isLazyLoad
} // foreach
$script .= "
View
1 src/Propel/Generator/Builder/Om/TableMapBuilder.php
@@ -123,6 +123,7 @@ protected function addConstants()
'nbLazyLoadColumns' => $this->getTable()->getNumLazyLoadColumns(),
'nbHydrateColumns' => $this->getTable()->getNumColumns() - $this->getTable()->getNumLazyLoadColumns(),
'peerClassName' => $this->getStubPeerBuilder()->getFullyQualifiedClassName(),
+ 'columns' => $this->getTable()->getColumns(),
));
}
View
43 src/Propel/Generator/Builder/Om/templates/tableMapConstants.php
@@ -1,44 +1,51 @@
/**
- * The (dot-path) name of this class
- */
+ * The (dot-path) name of this class
+ */
const CLASS_NAME = '<?php echo $className ?>';
/**
- * The default database name for this class
- */
+ * The default database name for this class
+ */
const DATABASE_NAME = '<?php echo $dbName ?>';
/**
- * The table name for this class
- */
+ * The table name for this class
+ */
const TABLE_NAME = '<?php echo $tableName ?>';
/**
- * The related Propel class for this table
- */
+ * The related Propel class for this table
+ */
const OM_CLASS = '<?php echo $tablePhpName ?>';
/**
- * A class that can be returned by this peer
- */
+ * A class that can be returned by this peer
+ */
const CLASS_DEFAULT = '<?php echo $classPath ?>';
/**
- * The related TableMap class for this table
- */
+ * The related TableMap class for this table
+ */
const PEER_CLASS = '<?php echo $peerClassName ?>';
/**
- * The total number of columns
- */
+ * The total number of columns
+ */
const NUM_COLUMNS = <?php echo $nbColumns ?>;
/**
- * The number of lazy-loaded columns
- */
+ * 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)
- */
+ * The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS)
+ */
const NUM_HYDRATE_COLUMNS = <?php echo $nbHydrateColumns ?>;
+<?php foreach ($columns as $col) : ?>
+
+ /**
+ * the column name for the <?php echo strtoupper($col->getName()) ?> field
+ */
+ const <?php echo $col->getConstantColumnName() ?> = '<?php echo $tableName ?>.<?php echo strtoupper($col->getName()) ?>';
+<?php endforeach; ?>
View
2 src/Propel/Generator/Model/Column.php
@@ -469,7 +469,7 @@ public function setMutatorVisibility($visibility)
*/
public function getConstantName()
{
- $classname = $this->parentTable->getPhpName() . 'Peer';
+ $classname = $this->parentTable->getPhpName() . 'TableMap';
$const = $this->getConstantColumnName();
return $classname.'::'.$const;

0 comments on commit e2e7673

Please sign in to comment.
Something went wrong with that request. Please try again.