Skip to content
Browse files

Merge branch 'master' into ormigo

* master:
  Fixes #345
  Allow the QuickGenerator to use another Platform
  Change fallback order in getTableByPhpName(). Fixes #385
  Fix initialization of internal iterator for getRelCol. fix #460
  Add a test for initialization of internal iterator for related object collection getter fix #460
  Fix PR #544
  teaching propel to clear UP and DOWN when calling clearAllReferences(true) we have infinite recursion prevention already covered also we add an optional param to clearInstancePool. if passes as true it will clearAllReferences(true) on every instance before clearing it.
  Fix CS
  Fix cast in setters. Should fix #283
  Fix inconsistency for BIGINT. Fixes #459
  Use model prefix in QueryInheritanceBuilder, fixes #542
  fix variable name on boolean filter methods
  Tests for improved ENUM handling
  Improved getValueSet() method, added ENUM getters for SQL value, set Query filter to use SQL getters
  Add PHP 5.5 to travis config
  Update generator/lib/builder/om/PHP5PeerBuilder.php
  sqlType="enum(..)" now set the valueSet attribute it is not required to use Propel::ENUM as type
  • Loading branch information...
2 parents 0f7cb67 + 97bd6ab commit 7d94f67ed0a0f94e8703636d98da8951c0b5345f @havvg havvg committed
View
5 .travis.yml
@@ -3,10 +3,15 @@ language: php
php:
- 5.3
- 5.4
+ - 5.5
env:
- DB=mysql DB_USER=root
+matrix:
+ allow_failures:
+ - php: 5.5
+
before_script:
# MySQL
- sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'SET FOREIGN_KEY_CHECKS = 0; DROP DATABASE IF EXISTS test; DROP SCHEMA IF EXISTS second_hand_books; DROP SCHEMA IF EXISTS contest; DROP DATABASE IF EXISTS reverse_bookstore; DROP SCHEMA IF EXISTS bookstore_schemas; SET FOREIGN_KEY_CHECKS = 1;'; fi"
View
32 generator/lib/builder/om/PHP5ObjectBuilder.php
@@ -407,6 +407,7 @@ protected function addAttributes(&$script)
$this->addAlreadyInSaveAttribute($script);
$this->addAlreadyInValidationAttribute($script);
+ $this->addAlreadyInClearAllReferencesDeepAttribute($script);
// apply behaviors
$this->applyBehaviorModifier('objectAttributes', $script, " ");
@@ -1856,7 +1857,7 @@ protected function addDefaultMutator(&$script, Column $col)
// checking in mutators.
if ($col->isPhpPrimitiveType()) {
$script .= "
- if (\$v !== null) {
+ if (\$v !== null && is_numeric(\$v)) {
\$v = (".$col->getPhpType().") \$v;
}
";
@@ -3766,6 +3767,7 @@ public function get$relCol(\$criteria = null, PropelPDO \$con = null)
\$this->{$collName}Partial = true;
}
+ \$$collName"."->getInternalIterator()->rewind();
return \$$collName;
}
@@ -5087,6 +5089,21 @@ protected function addAlreadyInValidationAttribute(&$script)
}
/**
+ * Adds the $alreadyInValidation attribute, which prevents attempting to re-validate the same object.
+ * @param string &$script The script will be modified in this method.
+ */
+ protected function addAlreadyInClearAllReferencesDeepAttribute(&$script)
+ {
+ $script .= "
+ /**
+ * Flag to prevent endless clearAllReferences(\$deep=true) loop, if this object is referenced
+ * @var boolean
+ */
+ protected \$alreadyInClearAllReferencesDeep = false;
+";
+ }
+
+ /**
* Adds the validate() method.
* @param string &$script The script will be modified in this method.
*/
@@ -5445,6 +5462,7 @@ public function clear()
$script .= "
\$this->alreadyInSave = false;
\$this->alreadyInValidation = false;
+ \$this->alreadyInClearAllReferencesDeep = false;
\$this->clearAllReferences();";
if ($this->hasDefaultValues()) {
@@ -5481,7 +5499,8 @@ protected function addClearAllReferences(&$script)
*/
public function clearAllReferences(\$deep = false)
{
- if (\$deep) {";
+ if (\$deep && !\$this->alreadyInClearAllReferencesDeep) {
+ \$this->alreadyInClearAllReferencesDeep = true;";
$vars = array();
foreach ($this->getTable()->getReferrers() as $refFK) {
if ($refFK->isLocalPrimaryKey()) {
@@ -5513,7 +5532,16 @@ public function clearAllReferences(\$deep = false)
$vars[] = $varName;
}
+ foreach ($table->getForeignKeys() as $fk) {
+ $varName = $this->getFKVarName($fk);
+ $script .= "
+ if (\$this->$varName instanceof Persistent) {
+ \$this->{$varName}->clearAllReferences(\$deep);
+ }";
+ }
$script .= "
+
+ \$this->alreadyInClearAllReferencesDeep = false;
} // if (\$deep)
";
View
72 generator/lib/builder/om/PHP5PeerBuilder.php
@@ -270,7 +270,7 @@ protected function addColumnNameConstants(&$script)
protected function addEnumColumnConstants(&$script)
{
foreach ($this->getTable()->getColumns() as $col) {
- if ($col->isEnumType()) {
+ if ($col->isEnumType() || $col->getValueSet()) {
$script .= "
/** The enumerated values for the " . $col->getName() . " field */";
foreach ($col->getValueSet() as $value) {
@@ -394,7 +394,7 @@ protected function addEnumColumnAttributes(&$script)
/** The enumerated values for this table */
protected static \$enumValueSets = array(";
foreach ($this->getTable()->getColumns() as $col) {
- if ($col->isEnumType()) {
+ if ($col->isEnumType() || $col->getValueSet()) {
$script .= "
".$this->getPeerClassname()."::" . $this->getColumnName($col) ." => array(
";
@@ -499,12 +499,68 @@ public static function getValueSet(\$colname)
{
\$valueSets = static::getValueSets();
+ if (!isset(\$valueSets[\$colname])) {
+ throw new PropelException(sprintf('Column \"%s\" has no ValueSet.', \$colname));
+ }
+
return \$valueSets[\$colname];
}
";
}
/**
+ * Adds the getSqlValueForEnum() method.
+ * @param string &$script The script will be modified in this method.
+ */
+ protected function addGetSqlValueForEnum(&$script)
+ {
+ $this->declareClassFromBuilder($this->getTableMapBuilder());
+ $script .= "
+ /**
+ * Gets the SQL value for the ENUM column value
+ *
+ * @param string \$colname ENUM column name.
+ * @param string \$enumVal ENUM value.
+ *
+ * @return int SQL value
+ */
+ public static function getSqlValueForEnum(\$colname, \$enumVal)
+ {
+ \$values = ".$this->getPeerClassname()."::getValueSet(\$colname);
+ if (!in_array(\$enumVal, \$values)) {
+ throw new PropelException(sprintf('Value \"%s\" is not accepted in this enumerated column', \$colname));
+ }
+ return array_search(\$enumVal, \$values);
+ }
+";
+ }
+
+ /**
+ * Adds methods for ENUM columns.
+ * @param string &$script The script will be modified in this method.
+ */
+ protected function addEnumMethods(&$script)
+ {
+ foreach ($this->getTable()->getColumns() as $col) {
+ /* @var $col Column */
+ if ($col->isEnumType()) {
+ $script .= "
+ /**
+ * Gets the SQL value for ".$col->getPhpName()." ENUM value
+ *
+ * @param string \$enumVal ENUM value to get SQL value for
+ * @return int SQL value
+ */
+ public static function get{$col->getPhpName()}SqlValue(\$enumVal)
+ {
+ return {$this->getPeerClassname()}::getSqlValueForEnum({$this->getColumnConstant($col)}, \$enumVal);
+ }
+";
+ }
+ }
+ }
+
+ /**
* Adds the buildTableMap() method.
* @param string &$script The script will be modified in this method.
*/
@@ -757,7 +813,7 @@ protected function addDoSelectStmt(&$script)
/**
* Prepares the Criteria object and uses the parent doSelect() method to execute a PDOStatement.
*
- * Use this method directly if you want to work with an executed statement durirectly (for example
+ * Use this method directly if you want to work with an executed statement directly (for example
* to perform your own object hydration).
*
* @param Criteria \$criteria The Criteria object used to build the SELECT statement.
@@ -932,8 +988,15 @@ protected function addClearInstancePool(&$script)
*
* @return void
*/
- public static function clearInstancePool()
+ public static function clearInstancePool(\$and_clear_all_references = false)
{
+ if (\$and_clear_all_references)
+ {
+ foreach (".$this->getPeerClassname()."::\$instances as \$instance)
+ {
+ \$instance->clearAllReferences(true);
+ }
+ }
".$this->getPeerClassname()."::\$instances = array();
}
";
@@ -2049,6 +2112,7 @@ protected function addSelectMethods(&$script)
parent::addSelectMethods($script);
+ $this->addEnumMethods($script);
$this->addDoCountJoin($script);
$this->addDoSelectJoin($script);
View
2 generator/lib/builder/om/PHP5TableMapBuilder.php
@@ -226,7 +226,7 @@ public function initialize()
\$this->addColumn('$cup', '$cfc', '".$col->getType()."', ".var_export($col->isNotNull(), true).", ".$size.", $default);";
}
} // if col-is prim key
- if ($col->isEnumType()) {
+ if ($col->getValueSet()) {
$script .= "
\$this->getColumn('$cup', false)->setValueSet(" . var_export($col->getValueSet(), true). ");";
}
View
1 generator/lib/builder/om/PeerBuilder.php
@@ -146,6 +146,7 @@ protected function addClassBody(&$script)
if ($table->hasEnumColumns()) {
$this->addGetValueSets($script);
$this->addGetValueSet($script);
+ $this->addGetSqlValueForEnum($script);
}
if (!$table->isAlias()) {
View
13 generator/lib/builder/om/QueryBuilder.php
@@ -900,19 +900,12 @@ public function filterBy$colPhpName(\$$variableName = null, \$comparison = null)
}";
} elseif ($col->getType() == PropelTypes::ENUM) {
$script .= "
- \$valueSet = " . $this->getPeerClassname() . "::getValueSet(" . $this->getColumnConstant($col) . ");
if (is_scalar(\$$variableName)) {
- if (!in_array(\$$variableName, \$valueSet)) {
- throw new PropelException(sprintf('Value \"%s\" is not accepted in this enumerated column', \$$variableName));
- }
- \$$variableName = array_search(\$$variableName, \$valueSet);
+ \$$variableName = {$this->getPeerClassname()}::getSqlValueForEnum({$this->getColumnConstant($col)}, \$$variableName);
} elseif (is_array(\$$variableName)) {
\$convertedValues = array();
foreach (\$$variableName as \$value) {
- if (!in_array(\$value, \$valueSet)) {
- throw new PropelException(sprintf('Value \"%s\" is not accepted in this enumerated column', \$value));
- }
- \$convertedValues []= array_search(\$value, \$valueSet);
+ \$convertedValues[] = {$this->getPeerClassname()}::getSqlValueForEnum({$this->getColumnConstant($col)}, \$value);
}
\$$variableName = \$convertedValues;
if (null === \$comparison) {
@@ -932,7 +925,7 @@ public function filterBy$colPhpName(\$$variableName = null, \$comparison = null)
} elseif ($col->isBooleanType()) {
$script .= "
if (is_string(\$$variableName)) {
- \$$colName = in_array(strtolower(\$$variableName), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true;
+ \$$variableName = in_array(strtolower(\$$variableName), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true;
}";
}
$script .= "
View
4 generator/lib/builder/om/QueryInheritanceBuilder.php
@@ -240,9 +240,9 @@ public function preDelete(PropelPDO \$con)
protected function getClassKeyCondition()
{
$child = $this->getChild();
- $col = $child->getColumn();
+ $col = $child->getColumn();
- return "\$this->addUsingAlias(" . $col->getConstantName() . ", " . $this->getPeerClassname()."::CLASSKEY_".strtoupper($child->getKey()).");";
+ return "\$this->addUsingAlias(" . $this->getColumnConstant($col) . ", " . $this->getPeerClassname()."::CLASSKEY_".strtoupper($child->getKey()).");";
}
protected function addDoDeleteAll(&$script)
View
47 generator/lib/config/QuickGeneratorConfig.php
@@ -10,40 +10,43 @@
require_once dirname(__FILE__) . '/GeneratorConfig.php';
require_once dirname(__FILE__) . '/GeneratorConfigInterface.php';
+require_once dirname(__FILE__) . '/../platform/PropelPlatformInterface.php';
require_once dirname(__FILE__) . '/../platform/SqlitePlatform.php';
/**
- *
- * @package propel.generator.config
+ * @package propel.generator.config
*/
class QuickGeneratorConfig implements GeneratorConfigInterface
{
protected $builders = array(
'peer' => 'PHP5PeerBuilder',
'object' => 'PHP5ObjectBuilder',
- 'objectstub' => 'PHP5ExtensionObjectBuilder',
- 'peerstub' => 'PHP5ExtensionPeerBuilder',
- 'objectmultiextend' => 'PHP5MultiExtendObjectBuilder',
- 'tablemap' => 'PHP5TableMapBuilder',
+ 'objectstub' => 'PHP5ExtensionObjectBuilder',
+ 'peerstub' => 'PHP5ExtensionPeerBuilder',
+ 'objectmultiextend' => 'PHP5MultiExtendObjectBuilder',
+ 'tablemap' => 'PHP5TableMapBuilder',
'query' => 'QueryBuilder',
- 'querystub' => 'ExtensionQueryBuilder',
- 'queryinheritance' => 'QueryInheritanceBuilder',
- 'queryinheritancestub' => 'ExtensionQueryInheritanceBuilder',
- 'interface' => 'PHP5InterfaceBuilder',
+ 'querystub' => 'ExtensionQueryBuilder',
+ 'queryinheritance' => 'QueryInheritanceBuilder',
+ 'queryinheritancestub' => 'ExtensionQueryInheritanceBuilder',
+ 'interface' => 'PHP5InterfaceBuilder',
'node' => 'PHP5NodeBuilder',
- 'nodepeer' => 'PHP5NodePeerBuilder',
- 'nodestub' => 'PHP5ExtensionNodeBuilder',
- 'nodepeerstub' => 'PHP5ExtensionNodePeerBuilder',
- 'nestedset' => 'PHP5NestedSetBuilder',
- 'nestedsetpeer' => 'PHP5NestedSetPeerBuilder',
+ 'nodepeer' => 'PHP5NodePeerBuilder',
+ 'nodestub' => 'PHP5ExtensionNodeBuilder',
+ 'nodepeerstub' => 'PHP5ExtensionNodePeerBuilder',
+ 'nestedset' => 'PHP5NestedSetBuilder',
+ 'nestedsetpeer' => 'PHP5NestedSetPeerBuilder',
);
- protected $buildProperties = array();
+ protected $buildProperties = array();
+
+ private $generatorConfig = null;
- private $generatorConfig = null;
+ private $configuredPlatform = null;
- public function __construct()
+ public function __construct(PropelPlatformInterface $platform = null)
{
+ $this->configuredPlatform = $platform;
$this->setBuildProperties($this->parsePseudoIniFile(dirname(__FILE__) . '/../../default.properties'));
}
@@ -156,7 +159,13 @@ public function setBuildProperty($name, $value)
*/
public function getConfiguredPlatform(PDO $con = null, $database = null)
{
- return new SqlitePlatform($con);
+ if (null === $this->configuredPlatform) {
+ return new SqlitePlatform($con);
+ }
+
+ $this->configuredPlatform->setConnection($con);
+
+ return $this->configuredPlatform;
}
/**
View
11 generator/lib/model/Column.php
@@ -240,6 +240,17 @@ protected function setupObject()
}
$valueSet = array_map('trim', $valueSet);
$this->valueSet = $valueSet;
+ } elseif (preg_match('/enum\((.*?)\)/i', $this->getAttribute('sqlType', ''), $matches)) {
+ if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
+ $valueSet = str_getcsv($matches['1'], ',', '\'');
+ } else {
+ // unfortunately, no good fallback for PHP 5.2
+ $valueSet = array();
+ foreach (explode(',', $matches['1']) as $value) {
+ $valueSet[] = trim($value, " '");
+ }
+ }
+ $this->valueSet = $valueSet;
}
$this->inheritanceType = $this->getAttribute("inheritance");
View
2 generator/lib/model/PropelTypes.php
@@ -188,7 +188,7 @@ class PropelTypes
self::TINYINT => PDO::PARAM_INT,
self::SMALLINT => PDO::PARAM_INT,
self::INTEGER => PDO::PARAM_INT,
- self::BIGINT => PDO::PARAM_INT,
+ self::BIGINT => PDO::PARAM_STR,
self::REAL => PDO::PARAM_STR,
self::FLOAT => PDO::PARAM_STR,
self::DOUBLE => PDO::PARAM_STR,
View
5 generator/lib/model/Table.php
@@ -506,7 +506,7 @@ public function addExtraIndices()
foreach ($this->getForeignKeys() as $foreignKey) {
$localColumns = $foreignKey->getLocalColumnObjects();
$localColumnsHash = $this->getColumnList($localColumns);
- if (!array_key_exists($localColumnsHash, $_indices)) {
+ if (!empty($localColumnsHash) && !array_key_exists($localColumnsHash, $_indices)) {
// no matching index defined in the schema, so we have to create one. MySQL needs indices on any columns that serve as foreign keys. these are not auto-created prior to 4.1.2
$index = new Index();
$index->setName(substr_replace($foreignKey->getName(), 'FI_', strrpos($foreignKey->getName(), 'FK_'), 3));
@@ -1501,8 +1501,9 @@ public function getNumLazyLoadColumns()
*/
public function hasEnumColumns()
{
+
foreach ($this->getColumns() as $col) {
- if ($col->isEnumType()) {
+ if ($col->isEnumType() || $col->getValueSet()) {
return true;
}
}
View
2 generator/lib/util/PropelQuickBuilder.php
@@ -71,7 +71,7 @@ public function getConfig()
{
if (null === $this->config) {
require_once dirname(__FILE__) . '/../config/QuickGeneratorConfig.php';
- $this->config = new QuickGeneratorConfig();
+ $this->config = new QuickGeneratorConfig($this->getPlatform());
}
return $this->config;
View
22 runtime/lib/collection/PropelOnDemandIterator.php
@@ -17,20 +17,22 @@
class PropelOnDemandIterator implements Iterator
{
/**
- * @var PropelObjectFormatter
+ * @var PropelObjectFormatter
*/
protected $formatter;
/**
- * @var PDOStatement
+ * @var PDOStatement
*/
protected $stmt;
- protected
- $currentRow,
- $currentKey = -1,
- $isValid = null,
- $enableInstancePoolingOnFinish = false;
+ protected $currentRow;
+
+ protected $currentKey = -1;
+
+ protected $isValid = null;
+
+ protected $enableInstancePoolingOnFinish = false;
/**
* @param PropelFormatter $formatter
@@ -39,7 +41,7 @@ class PropelOnDemandIterator implements Iterator
public function __construct(PropelFormatter $formatter, PDOStatement $stmt)
{
$this->formatter = $formatter;
- $this->stmt = $stmt;
+ $this->stmt = $stmt;
$this->enableInstancePoolingOnFinish = Propel::disableInstancePooling();
}
@@ -59,13 +61,11 @@ public function count()
return $this->stmt->rowCount();
}
- // Iterator Interface
-
/**
* Gets the current Model object in the collection
* This is where the hydration takes place.
*
- * @see PropelObjectFormatter::getAllObjectsFromRow()
+ * @see PropelObjectFormatter::getAllObjectsFromRow()
*
* @return BaseObject
*/
View
319 runtime/lib/map/DatabaseMap.php
@@ -26,169 +26,168 @@
*/
class DatabaseMap
{
+ /** @var string Name of the database. */
+ protected $name;
+
+ /** @var array TableMap[] Tables in the database, using table name as key */
+ protected $tables = array();
+
+ /** @var array TableMap[] Tables in the database, using table phpName as key */
+ protected $tablesByPhpName = array();
+
+ /**
+ * Constructor.
+ *
+ * @param string $name Name of the database.
+ */
+ public function __construct($name)
+ {
+ $this->name = $name;
+ }
+
+ /**
+ * Get the name of this database.
+ *
+ * @return string The name of the database.
+ */
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ /**
+ * Add a new table to the database by name.
+ *
+ * @param string $tableName The name of the table.
+ * @return TableMap The newly created TableMap.
+ */
+ public function addTable($tableName)
+ {
+ $this->tables[$tableName] = new TableMap($tableName, $this);
+
+ return $this->tables[$tableName];
+ }
+
+ /**
+ * Add a new table object to the database.
+ *
+ * @param TableMap $table The table to add
+ */
+ public function addTableObject(TableMap $table)
+ {
+ $table->setDatabaseMap($this);
+ $this->tables[$table->getName()] = $table;
+ $this->tablesByPhpName[$table->getClassname()] = $table;
+ }
+
+ /**
+ * Add a new table to the database, using the tablemap class name.
+ *
+ * @param string $tableMapClass The name of the table map to add
+ * @return TableMap The TableMap object
+ */
+ public function addTableFromMapClass($tableMapClass)
+ {
+ $table = new $tableMapClass();
+ if (!$this->hasTable($table->getName())) {
+ $this->addTableObject($table);
+
+ return $table;
+ } else {
+ return $this->getTable($table->getName());
+ }
+ }
- /** @var string Name of the database. */
- protected $name;
-
- /** @var array TableMap[] Tables in the database, using table name as key */
- protected $tables = array();
-
- /** @var array TableMap[] Tables in the database, using table phpName as key */
- protected $tablesByPhpName = array();
-
- /**
- * Constructor.
- *
- * @param string $name Name of the database.
- */
- public function __construct($name)
- {
- $this->name = $name;
- }
-
- /**
- * Get the name of this database.
- *
- * @return string The name of the database.
- */
- public function getName()
- {
- return $this->name;
- }
-
- /**
- * Add a new table to the database by name.
- *
- * @param string $tableName The name of the table.
- * @return TableMap The newly created TableMap.
- */
- public function addTable($tableName)
- {
- $this->tables[$tableName] = new TableMap($tableName, $this);
-
- return $this->tables[$tableName];
- }
-
- /**
- * Add a new table object to the database.
- *
- * @param TableMap $table The table to add
- */
- public function addTableObject(TableMap $table)
- {
- $table->setDatabaseMap($this);
- $this->tables[$table->getName()] = $table;
- $this->tablesByPhpName[$table->getClassname()] = $table;
- }
-
- /**
- * Add a new table to the database, using the tablemap class name.
- *
- * @param string $tableMapClass The name of the table map to add
- * @return TableMap The TableMap object
- */
- public function addTableFromMapClass($tableMapClass)
- {
- $table = new $tableMapClass();
- if (!$this->hasTable($table->getName())) {
- $this->addTableObject($table);
-
- return $table;
- } else {
- return $this->getTable($table->getName());
+ /**
+ * Does this database contain this specific table?
+ *
+ * @param string $name The String representation of the table.
+ * @return boolean True if the database contains the table.
+ */
+ public function hasTable($name)
+ {
+ return array_key_exists($name, $this->tables);
}
- }
-
- /**
- * Does this database contain this specific table?
- *
- * @param string $name The String representation of the table.
- * @return boolean True if the database contains the table.
- */
- public function hasTable($name)
- {
- return array_key_exists($name, $this->tables);
- }
-
- /**
- * Get a TableMap for the table by name.
- *
- * @param string $name Name of the table.
- * @return TableMap A TableMap
- * @throws PropelException if the table is undefined
- */
- public function getTable($name)
- {
- if (!isset($this->tables[$name])) {
- throw new PropelException("Cannot fetch TableMap for undefined table: " . $name );
+
+ /**
+ * Get a TableMap for the table by name.
+ *
+ * @param string $name Name of the table.
+ * @return TableMap A TableMap
+ * @throws PropelException if the table is undefined
+ */
+ public function getTable($name)
+ {
+ if (!isset($this->tables[$name])) {
+ throw new PropelException("Cannot fetch TableMap for undefined table: " . $name );
+ }
+
+ return $this->tables[$name];
+ }
+
+ /**
+ * Get a TableMap[] of all of the tables in the database.
+ *
+ * @return array A TableMap[].
+ */
+ public function getTables()
+ {
+ return $this->tables;
+ }
+
+ /**
+ * Get a ColumnMap for the column by name.
+ * Name must be fully qualified, e.g. book.AUTHOR_ID
+ *
+ * @param $qualifiedColumnName Name of the column.
+ * @return ColumnMap A TableMap
+ * @throws PropelException if the table is undefined, or if the table is undefined
+ */
+ public function getColumn($qualifiedColumnName)
+ {
+ list($tableName, $columnName) = explode('.', $qualifiedColumnName);
+
+ return $this->getTable($tableName)->getColumn($columnName, false);
+ }
+
+ // deprecated methods
+
+ /**
+ * Does this database contain this specific table?
+ *
+ * @deprecated Use hasTable() instead
+ * @param string $name The String representation of the table.
+ * @return boolean True if the database contains the table.
+ */
+ public function containsTable($name)
+ {
+ return $this->hasTable($name);
+ }
+
+ public function getTableByPhpName($phpName)
+ {
+ if (array_key_exists($phpName, $this->tablesByPhpName)) {
+ return $this->tablesByPhpName[$phpName];
+ } elseif (class_exists($tmClass = substr_replace($phpName, '\\map\\', strrpos($phpName, '\\'), 1) . 'TableMap')) {
+ $this->addTableFromMapClass($tmClass);
+
+ return $this->tablesByPhpName[$phpName];
+ } elseif (class_exists($tmClass = $phpName . 'TableMap')) {
+ $this->addTableFromMapClass($tmClass);
+
+ return $this->tablesByPhpName[$phpName];
+ } else {
+ throw new PropelException("Cannot fetch TableMap for undefined table phpName: " . $phpName);
+ }
}
- return $this->tables[$name];
- }
-
- /**
- * Get a TableMap[] of all of the tables in the database.
- *
- * @return array A TableMap[].
- */
- public function getTables()
- {
- return $this->tables;
- }
-
- /**
- * Get a ColumnMap for the column by name.
- * Name must be fully qualified, e.g. book.AUTHOR_ID
- *
- * @param $qualifiedColumnName Name of the column.
- * @return ColumnMap A TableMap
- * @throws PropelException if the table is undefined, or if the table is undefined
- */
- public function getColumn($qualifiedColumnName)
- {
- list($tableName, $columnName) = explode('.', $qualifiedColumnName);
-
- return $this->getTable($tableName)->getColumn($columnName, false);
- }
-
- // deprecated methods
-
- /**
- * Does this database contain this specific table?
- *
- * @deprecated Use hasTable() instead
- * @param string $name The String representation of the table.
- * @return boolean True if the database contains the table.
- */
- public function containsTable($name)
- {
- return $this->hasTable($name);
- }
-
- public function getTableByPhpName($phpName)
- {
- if (array_key_exists($phpName, $this->tablesByPhpName)) {
- return $this->tablesByPhpName[$phpName];
- } elseif (class_exists($tmClass = $phpName . 'TableMap')) {
- $this->addTableFromMapClass($tmClass);
-
- return $this->tablesByPhpName[$phpName];
- } elseif (class_exists($tmClass = substr_replace($phpName, '\\map\\', strrpos($phpName, '\\'), 1) . 'TableMap')) {
- $this->addTableFromMapClass($tmClass);
-
- return $this->tablesByPhpName[$phpName];
- } else {
- throw new PropelException("Cannot fetch TableMap for undefined table phpName: " . $phpName);
+ /**
+ * Convenience method to get the DBAdapter registered with Propel for this database.
+ * @return DBAdapter
+ * @see Propel::getDB(string)
+ */
+ public function getDBAdapter()
+ {
+ return Propel::getDB($this->name);
}
- }
-
- /**
- * Convenience method to get the DBAdapter registered with Propel for this database.
- * @return DBAdapter
- * @see Propel::getDB(string)
- */
- public function getDBAdapter()
- {
- return Propel::getDB($this->name);
- }
}
View
79 test/testsuite/generator/behavior/nestedset/NestedSetBehaviorTest.php
@@ -1,7 +1,6 @@
<?php
-/*
- * $Id$
+/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -10,12 +9,14 @@
*/
require_once dirname(__FILE__) . '/../../../../tools/helpers/bookstore/BookstoreTestBase.php';
+require_once dirname(__FILE__) . '/../../../../../generator/lib/util/PropelQuickBuilder.php';
+require_once dirname(__FILE__) . '/../../../../../generator/lib/behavior/nestedset/NestedSetBehavior.php';
+require_once dirname(__FILE__) . '/../../../../../generator/lib/platform/MysqlPlatform.php';
/**
* Tests for NestedSetBehavior class
*
* @author François Zaninotto
- * @version $Revision$
* @package generator.behavior.nestedset
*/
class NestedSetBehaviorTest extends BookstoreTestBase
@@ -45,4 +46,76 @@ public function testParameters()
$this->assertTrue(method_exists('Table10', 'getScopeValue'), 'nested_set maps the scope_value getter with the tree_scope column when the use_scope parameter is true');
}
+ public function testGeneratedSqlForMySQL()
+ {
+ $schema = <<<XML
+<database name="default">
+ <table name="thread">
+ <column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" />
+ </table>
+ <table name="post">
+ <column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" />
+ <column name="body" type="VARCHAR" required="true" primaryString="true" />
+
+ <foreign-key foreignTable="thread" onDelete="cascade">
+ <reference local="thread_id" foreign="id" />
+ </foreign-key>
+
+ <behavior name="nested_set">
+ <parameter name="use_scope" value="true" />
+ <parameter name="scope_column" value="thread_id" />
+ </behavior>
+ </table>
+</database>
+XML;
+ $expectedSql = <<<SQL
+
+# This is a fix for InnoDB in MySQL >= 4.1.x
+# It "suspends judgement" for fkey relationships until are tables are set.
+SET FOREIGN_KEY_CHECKS = 0;
+
+-- ---------------------------------------------------------------------
+-- thread
+-- ---------------------------------------------------------------------
+
+DROP TABLE IF EXISTS `thread`;
+
+CREATE TABLE `thread`
+(
+ `id` INTEGER NOT NULL AUTO_INCREMENT,
+ PRIMARY KEY (`id`)
+) ENGINE=MyISAM;
+
+-- ---------------------------------------------------------------------
+-- post
+-- ---------------------------------------------------------------------
+
+DROP TABLE IF EXISTS `post`;
+
+CREATE TABLE `post`
+(
+ `id` INTEGER NOT NULL AUTO_INCREMENT,
+ `body` VARCHAR(255) NOT NULL,
+ `tree_left` INTEGER,
+ `tree_right` INTEGER,
+ `tree_level` INTEGER,
+ `thread_id` INTEGER,
+ PRIMARY KEY (`id`),
+ INDEX `post_FI_1` (`thread_id`),
+ CONSTRAINT `post_FK_1`
+ FOREIGN KEY (`thread_id`)
+ REFERENCES `thread` (`id`)
+ ON DELETE CASCADE
+) ENGINE=MyISAM;
+
+# This restores the fkey checks, after having unset them earlier
+SET FOREIGN_KEY_CHECKS = 1;
+
+SQL;
+ $builder = new PropelQuickBuilder();
+ $builder->setPlatform(new MysqlPlatform());
+ $builder->setSchema($schema);
+
+ $this->assertEquals($expectedSql, $builder->getSQL());
+ }
}
View
8 test/testsuite/generator/builder/om/GeneratedObjectRelTest.php
@@ -170,6 +170,14 @@ public function testManyToManyGetter()
$this->assertEquals(1, count($books), 'getCrossRefFK() accepts a query as first parameter');
}
+ public function testOneToManyGetter()
+ {
+ BookstoreDataPopulator::populate(null, true);
+ $author = AuthorQuery::create()->findOneByLastName('Grass');
+ $books = $author->getBooks(new Criteria());
+ $this->assertNotNull($books->getCurrent(), 'getRelCol() initialize the internal iterator at the beginning');
+ }
+
public function testManyToManyCounterExists()
{
$this->assertTrue(method_exists('BookClubList', 'countBooks'), 'Object generator correcly adds counter for the crossRefFk');
View
24 test/testsuite/generator/builder/om/GeneratedPeerEnumColumnTypeTest.php
@@ -67,4 +67,28 @@ public function testGetValueSet()
$expected = array('foo', 'bar', 'baz', '1', '4', '(', 'foo bar');
$this->assertEquals($expected, ComplexColumnTypeEntity103Peer::getValueSet(ComplexColumnTypeEntity103Peer::BAR));
}
+
+ /**
+ * @expectedException PropelException
+ */
+ public function testGetValueSetInvalidColumn()
+ {
+ ComplexColumnTypeEntity103Peer::getValueSet(ComplexColumnTypeEntity103Peer::ID);
+ }
+
+ public function testGetSqlValueForEnum()
+ {
+ $this->assertEquals(0, ComplexColumnTypeEntity103Peer::getSqlValueForEnum(ComplexColumnTypeEntity103Peer::BAR, ComplexColumnTypeEntity103Peer::BAR_FOO));
+ $this->assertEquals(1, ComplexColumnTypeEntity103Peer::getSqlValueForEnum(ComplexColumnTypeEntity103Peer::BAR, ComplexColumnTypeEntity103Peer::BAR_BAR));
+ $this->assertEquals(2, ComplexColumnTypeEntity103Peer::getSqlValueForEnum(ComplexColumnTypeEntity103Peer::BAR, ComplexColumnTypeEntity103Peer::BAR_BAZ));
+ $this->assertEquals(6, ComplexColumnTypeEntity103Peer::getSqlValueForEnum(ComplexColumnTypeEntity103Peer::BAR, ComplexColumnTypeEntity103Peer::BAR_FOO_BAR));
+ }
+
+ public function testEnumSqlGetters()
+ {
+ $this->assertEquals(0, ComplexColumnTypeEntity103Peer::getBarSqlValue(ComplexColumnTypeEntity103Peer::BAR_FOO));
+ $this->assertEquals(1, ComplexColumnTypeEntity103Peer::getBarSqlValue(ComplexColumnTypeEntity103Peer::BAR_BAR));
+ $this->assertEquals(2, ComplexColumnTypeEntity103Peer::getBarSqlValue(ComplexColumnTypeEntity103Peer::BAR_BAZ));
+ $this->assertEquals(6, ComplexColumnTypeEntity103Peer::getBarSqlValue(ComplexColumnTypeEntity103Peer::BAR_FOO_BAR));
+ }
}

0 comments on commit 7d94f67

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