示例#1
0
 public function setRelationMap(RelationMap $relationMap, $leftTableAlias = null, $relationAlias = null)
 {
     $leftCols = $relationMap->getLeftColumns();
     $rightCols = $relationMap->getRightColumns();
     $nbColumns = $relationMap->countColumnMappings();
     for ($i = 0; $i < $nbColumns; $i++) {
         $this->addExplicitCondition($leftCols[$i]->getTableName(), $leftCols[$i]->getName(), $leftTableAlias, $rightCols[$i]->getTableName(), $rightCols[$i]->getName(), $relationAlias, Criteria::EQUAL);
     }
     $this->relationMap = $relationMap;
     return $this;
 }
示例#2
0
 /**
  * Method from the TableMap API
  */
 public function getRelations()
 {
     // table maps
     $authorTable = new TableMap();
     $authorTable->setClassName('\\Foo\\Author');
     $resellerTable = new TableMap();
     $resellerTable->setClassName('\\Foo\\Reseller');
     // relations
     $mainAuthorRelation = new RelationMap('MainAuthor');
     $mainAuthorRelation->setType(RelationMap::MANY_TO_ONE);
     $mainAuthorRelation->setForeignTable($authorTable);
     $authorRelation = new RelationMap('Author');
     $authorRelation->setType(RelationMap::ONE_TO_MANY);
     $authorRelation->setForeignTable($authorTable);
     $resellerRelation = new RelationMap('Reseller');
     $resellerRelation->setType(RelationMap::MANY_TO_MANY);
     $resellerRelation->setLocalTable($resellerTable);
     return array($mainAuthorRelation, $authorRelation, $resellerRelation);
 }
示例#3
0
 /**
  * Adds a RelationMap to the table
  *
  * @param  string                          $name          The relation name
  * @param  string                          $tablePhpName  The related table name
  * @param  integer                         $type          The relation type (either RelationMap::MANY_TO_ONE, RelationMap::ONE_TO_MANY, or RelationMAp::ONE_TO_ONE)
  * @param  array                           $columnMapping An associative array mapping column names (local => foreign)
  * @param  string                          $onDelete      SQL behavior upon deletion ('SET NULL', 'CASCADE', ...)
  * @param  string                          $onUpdate      SQL behavior upon update ('SET NULL', 'CASCADE', ...)
  * @param  string                          $pluralName    Optional plural name for *_TO_MANY relationships
  * @return \Propel\Runtime\Map\RelationMap the built RelationMap object
  */
 public function addRelation($name, $tablePhpName, $type, $columnMapping = array(), $onDelete = null, $onUpdate = null, $pluralName = null)
 {
     // note: using phpName for the second table allows the use of DatabaseMap::getTableByPhpName()
     // and this method autoloads the TableMap if the table isn't loaded yet
     $relation = new RelationMap($name);
     $relation->setType($type);
     $relation->setOnUpdate($onUpdate);
     $relation->setOnDelete($onDelete);
     if (null !== $pluralName) {
         $relation->setPluralName($pluralName);
     }
     // set tables
     if (RelationMap::MANY_TO_ONE === $type) {
         $relation->setLocalTable($this);
         $relation->setForeignTable($this->dbMap->getTableByPhpName($tablePhpName));
     } else {
         $relation->setLocalTable($this->dbMap->getTableByPhpName($tablePhpName));
         $relation->setForeignTable($this);
         $columnMapping = array_flip($columnMapping);
     }
     // set columns
     foreach ($columnMapping as $local => $foreign) {
         $relation->addColumnMapping($relation->getLocalTable()->getColumn($local), $relation->getForeignTable()->getColumn($foreign));
     }
     $this->relations[$name] = $relation;
     return $relation;
 }
示例#4
0
 public function __toString()
 {
     return parent::toString() . ' tableMap: ' . ($this->tableMap ? get_class($this->tableMap) : 'null') . ' relationMap: ' . $this->relationMap->getName() . ' previousJoin: ' . ($this->previousJoin ? '(' . $this->previousJoin . ')' : 'null') . ' relationAlias: ' . $this->rightTableAlias;
 }
示例#5
0
 /**
  * Adds a RelationMap to the table
  *
  * @param  string                          $name          The relation name
  * @param  string                          $tablePhpName  The related table name
  * @param  integer                         $type          The relation type (either RelationMap::MANY_TO_ONE, RelationMap::ONE_TO_MANY, or RelationMAp::ONE_TO_ONE)
  * @param  array                           $joinConditionMapping Arrays in array defining a normalize join condition [[':foreign_id', ':id', '='], [':foreign_type', 'value', '=']]
  * @param  string                          $onDelete      SQL behavior upon deletion ('SET NULL', 'CASCADE', ...)
  * @param  string                          $onUpdate      SQL behavior upon update ('SET NULL', 'CASCADE', ...)
  * @param  string                          $pluralName    Optional plural name for *_TO_MANY relationships
  * @param  boolean                         $polymorphic    Optional plural name for *_TO_MANY relationships
  *
  * @return RelationMap the built RelationMap object
  */
 public function addRelation($name, $tablePhpName, $type, $joinConditionMapping = [], $onDelete = null, $onUpdate = null, $pluralName = null, $polymorphic = false)
 {
     // note: using phpName for the second table allows the use of DatabaseMap::getTableByPhpName()
     // and this method autoloads the TableMap if the table isn't loaded yet
     $relation = new RelationMap($name);
     $relation->setType($type);
     $relation->setOnUpdate($onUpdate);
     $relation->setOnDelete($onDelete);
     $relation->setPolymorphic($polymorphic);
     if (null !== $pluralName) {
         $relation->setPluralName($pluralName);
     }
     // set tables
     if (RelationMap::MANY_TO_ONE === $type) {
         $relation->setLocalTable($this);
         $relation->setForeignTable($this->dbMap->getTableByPhpName($tablePhpName));
     } else {
         $relation->setLocalTable($this->dbMap->getTableByPhpName($tablePhpName));
         $relation->setForeignTable($this);
     }
     // set columns
     foreach ($joinConditionMapping as $map) {
         list($local, $foreign) = $map;
         $relation->addColumnMapping($this->getColumnOrValue($local, $relation->getLocalTable()), $this->getColumnOrValue($foreign, $relation->getForeignTable()));
     }
     $this->relations[$name] = $relation;
     return $relation;
 }