Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't fully reset query objects. #653

Merged
merged 3 commits into from
Apr 11, 2013
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions generator/lib/builder/om/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,15 +362,14 @@ public static function create(\$modelAlias = null, \$criteria = null)
*/
protected function addFactoryBody(&$script)
{
$table = $this->getTable();
$classname = $this->getNewStubQueryBuilder($this->getTable())->getClassname();
$script .= "
if (\$criteria instanceof " . $classname . ") {
return \$criteria;
}
\$query = new " . $classname . "();
if (null !== \$modelAlias) {
\$query->setModelAlias(\$modelAlias);
}
\$query = new " . $classname . "('" . $table->getDatabase()->getName() . "', '" . addslashes($this->getNewStubObjectBuilder($table)->getFullyQualifiedClassname()) . "', \$modelAlias);

if (\$criteria instanceof Criteria) {
\$query->mergeWith(\$criteria);
}
Expand Down
32 changes: 25 additions & 7 deletions runtime/lib/map/RelationMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,31 @@
*/
class RelationMap
{
// types
const MANY_TO_ONE = 1;
const ONE_TO_MANY = 2;
const ONE_TO_ONE = 3;
const MANY_TO_MANY = 4;

const
// types
MANY_TO_ONE = 1, ONE_TO_MANY = 2, ONE_TO_ONE = 3, MANY_TO_MANY = 4, // representations
LOCAL_TO_FOREIGN = 0, LEFT_TO_RIGHT = 1;
// representations
const LOCAL_TO_FOREIGN = 0;
const LEFT_TO_RIGHT = 1;

protected $name, $pluralName, $type, $localTable, $foreignTable, $localColumns = array(), $foreignColumns = array(), $onUpdate, $onDelete;
protected $name;
protected $pluralName;
protected $type;
protected $localTable;
protected $foreignTable;
/**
* @var ColumnMap[]
*/
protected $localColumns = array();
/**
* @var ColumnMap[]
*/
protected $foreignColumns = array();
protected $onUpdate;
protected $onDelete;

/**
* Constructor.
Expand Down Expand Up @@ -229,7 +247,7 @@ public function getForeignColumns()
/**
* Get the left columns of the relation
*
* @return array of ColumnMap objects
* @return ColumnMap[]
*/
public function getLeftColumns()
{
Expand All @@ -239,7 +257,7 @@ public function getLeftColumns()
/**
* Get the right columns of the relation
*
* @return array of ColumnMap objects
* @return ColumnMap[]
*/
public function getRightColumns()
{
Expand Down
45 changes: 29 additions & 16 deletions runtime/lib/map/TableMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,29 @@ class TableMap
/**
* Columns in the table
*
* @var array TableMap[]
* @var ColumnMap[]
*/
protected $columns = array();

/**
* Columns in the table, using table phpName as key
*
* @var array TableMap[]
* @var ColumnMap[]
*/
protected $columnsByPhpName = array();

/**
* Columns in the table, using as key
*
* @var array TableMap[]
* @var ColumnMap[]
*/
protected $columnsByInsensitiveCase = array();

// The database this table belongs to
/**
* The database this table belongs to
*
* @var DatabaseMap
*/
protected $dbMap;

// The name of the table
Expand Down Expand Up @@ -77,7 +81,11 @@ class TableMap
// The foreign key columns in the table
protected $foreignKeys = array();

// The relationships in the table
/**
* The relationships in the table
*
* @var RelationMap[]
*/
protected $relations = array();

// Relations are lazy loaded. This property tells if the relations are loaded or not
Expand Down Expand Up @@ -283,13 +291,14 @@ public function getPrimaryKeyMethodInfo()
/**
* Add a column to the table.
*
* @param string name A String with the column name.
* @param string $name A string with the column name.
* @param string $phpName A string specifying php name.
* @param string $type A string specifying the Propel type.
* @param boolean $isNotNull Whether column does not allow NULL values.
* @param int $size An int specifying the size.
* @param boolean $pk True if column is a primary key.
* @param string $fkTable A String with the foreign key table name.
* @param $fkColumn A String with the foreign key column name.
* @param string $fkColumn A String with the foreign key column name.
* @param string $defaultValue The default value for this column.
*
* @return ColumnMap The newly created column.
Expand Down Expand Up @@ -422,7 +431,7 @@ public function getColumnByInsensitiveCase($colName)
/**
* Get a ColumnMap[] of the columns in this table.
*
* @return array A ColumnMap[].
* @return ColumnMap[]
*/
public function getColumns()
{
Expand All @@ -432,10 +441,12 @@ public function getColumns()
/**
* Add a primary key column to this Table.
*
* @param string $columnName A String with the column name.
* @param string $type A string specifying the Propel type.
* @param boolean $isNotNull Whether column does not allow NULL values.
* @param $size An int specifying the size.
* @param string $columnName A string with the column name.
* @param string $phpName A string with the php name.
* @param string $type A string specifying the Propel type.
* @param boolean $isNotNull Whether column does not allow NULL values.
* @param int $size An int specifying the size.
* @param string $defaultValue
*
* @return ColumnMap Newly added PrimaryKey column.
*/
Expand All @@ -448,6 +459,7 @@ public function addPrimaryKey($columnName, $phpName, $type, $isNotNull = false,
* Add a foreign key column to the table.
*
* @param string $columnName A String with the column name.
* @param string $phpName A string with the php name.
* @param string $type A string specifying the Propel type.
* @param string $fkTable A String with the foreign key table name.
* @param string $fkColumn A String with the foreign key column name.
Expand All @@ -466,6 +478,7 @@ public function addForeignKey($columnName, $phpName, $type, $fkTable, $fkColumn,
* Add a foreign primary key column to the table.
*
* @param string $columnName A String with the column name.
* @param string $phpName A string with the php name.
* @param string $type A string specifying the Propel type.
* @param string $fkTable A String with the foreign key table name.
* @param string $fkColumn A String with the foreign key column name.
Expand Down Expand Up @@ -635,7 +648,7 @@ public function getRelation($name)
* Gets the RelationMap objects of the table
* This method will build the relations if they are not built yet
*
* @return Array list of RelationMap objects
* @return RelationMap[]
*/
public function getRelations()
{
Expand Down Expand Up @@ -720,7 +733,7 @@ protected function normalizeColName($name)
* Returns array of ColumnMap objects that make up the primary key for this table.
*
* @deprecated Use getPrimaryKeys instead
* @return array ColumnMap[]
* @return ColumnMap[]
*/
public function getPrimaryKeyColumns()
{
Expand Down Expand Up @@ -767,7 +780,7 @@ public function setPrefix($prefix)
*
* @deprecated Not used anywhere in Propel
*
* @param data A String.
* @param string $data
*
* @return boolean True if prefix is contained in data.
*/
Expand Down Expand Up @@ -798,7 +811,7 @@ protected function removePrefix($data)
*
* @deprecated Not used anywhere in Propel. At buildtime, use Column::generatePhpName() for that purpose
*
* @param data A String.
* @param string $data
*
* @return string A String with data processed.
*/
Expand Down
26 changes: 18 additions & 8 deletions runtime/lib/query/Criteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class Criteria implements IteratorAggregate
/**
* Storage of conditions data. Collection of Criterion objects.
*
* @var array
* @var Criterion[]
*/
protected $map = array();

Expand Down Expand Up @@ -193,6 +193,10 @@ class Criteria implements IteratorAggregate
* @var array
*/
protected $joins = array();

/**
* @var Criteria[]
*/
protected $selectQueries = array();

/**
Expand All @@ -209,7 +213,7 @@ class Criteria implements IteratorAggregate
*
* @var string
*/
protected $primaryTableName;
protected $primaryTableName = null;

/** The name of the database as given in the constructor. */
protected $originalDbName;
Expand All @@ -228,7 +232,7 @@ class Criteria implements IteratorAggregate
*
* @var string
*/
protected $queryComment;
protected $queryComment = null;

// flag to note that the criteria involves a blob.
protected $blobFlag = null;
Expand Down Expand Up @@ -283,7 +287,7 @@ public function getIterator()
/**
* Get the criteria map, i.e. the array of Criterions
*
* @return array
* @return Criterion[]
*/
public function getMap()
{
Expand Down Expand Up @@ -317,8 +321,11 @@ public function clear()
$this->blobFlag = null;
$this->aliases = array();
$this->useTransaction = false;
$this->ifLvlCount = false;
$this->wasTrue = false;
$this->conditionalProxy = null;
$this->defaultCombineOperator = Criteria::LOGICAL_AND;
$this->primaryTableName = null;
$this->queryComment = null;

}

/**
Expand Down Expand Up @@ -978,6 +985,7 @@ public function addMultipleJoin($conditions, $joinType = null)
if (null === $joinCondition) {
$joinCondition = $criterion;
} else {
/* @var $joinCondition Criterion */
$joinCondition = $joinCondition->addAnd($criterion);
}
}
Expand Down Expand Up @@ -1042,7 +1050,7 @@ public function addSelectQuery(Criteria $subQueryCriteria, $alias = null)
/**
* Checks whether this Criteria has a subquery.
*
* @return Boolean
* @return boolean
*/
public function hasSelectQueries()
{
Expand All @@ -1052,7 +1060,7 @@ public function hasSelectQueries()
/**
* Get the associative array of Criteria for the subQueries per alias.
*
* @return array Criteria[]
* @return Criteria[]
*/
public function getSelectQueries()
{
Expand Down Expand Up @@ -1087,6 +1095,7 @@ public function forgeSelectQueryAlias()
{
$aliasNumber = 0;
foreach ($this->getSelectQueries() as $c1) {
/* @var $c1 Criteria */
$aliasNumber += $c1->forgeSelectQueryAlias();
}

Expand Down Expand Up @@ -1556,6 +1565,7 @@ public function equals($crit)
return false;
}
foreach ($joins as $key => $join) {
/* @var $join Join */
if (!$join->equals($this->joins[$key])) {
return false;
}
Expand Down
7 changes: 5 additions & 2 deletions runtime/lib/query/Criterion.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Criterion

/** Comparison value.
*
* @var SqlEnum
* @var string
*/
protected $comparison;

Expand Down Expand Up @@ -59,6 +59,8 @@ class Criterion

/**
* other connected criteria and their conjunctions.
*
* @var Criterion[]
*/
protected $clauses = array();
protected $conjunctions = array();
Expand Down Expand Up @@ -576,12 +578,13 @@ private function addCriterionTable(Criterion $c, array &$s)
* get an array of all criterion attached to this
* recursing through all sub criterion
*
* @return array Criterion[]
* @return Criterion[]
*/
public function getAttachedCriterion()
{
$criterions = array($this);
foreach ($this->getClauses() as $criterion) {
/* @var $criterion Criterion */
$criterions = array_merge($criterions, $criterion->getAttachedCriterion());
}

Expand Down
Loading