protected function createTaggingTable()
 {
     $table = $this->getTable();
     $database = $table->getDatabase();
     $pks = $this->getTable()->getPrimaryKey();
     if (count($pks) > 1) {
         throw new EngineException('The Taggable behavior does not support tables with composite primary keys');
     }
     $taggingTableName = $this->getTaggingTableName();
     if ($database->hasTable($taggingTableName)) {
         $this->taggingTable = $database->getTable($taggingTableName);
     } else {
         $this->taggingTable = $database->addTable(array('name' => $taggingTableName, 'phpName' => $this->replaceTokens($this->getParameter('tagging_table_phpname')), 'package' => $table->getPackage(), 'schema' => $table->getSchema(), 'namespace' => '\\' . $table->getNamespace()));
         // every behavior adding a table should re-execute database behaviors
         // see bug 2188 http://www.propelorm.org/changeset/2188
         foreach ($database->getBehaviors() as $behavior) {
             $behavior->modifyDatabase();
         }
     }
     if ($this->taggingTable->hasColumn('tag_id')) {
         $tagFkColumn = $this->taggingTable->getColumn('tag_id');
     } else {
         $tagFkColumn = $this->taggingTable->addColumn(array('name' => 'tag_id', 'type' => PropelTypes::INTEGER, 'primaryKey' => 'true'));
     }
     if ($this->taggingTable->hasColumn($table->getName() . '_id')) {
         $objFkColumn = $this->taggingTable->getColumn($table->getName() . '_id');
     } else {
         $objFkColumn = $this->taggingTable->addColumn(array('name' => $table->getName() . '_id', 'type' => PropelTypes::INTEGER, 'primaryKey' => 'true'));
     }
     $this->taggingTable->setIsCrossRef(true);
     $fkTag = new ForeignKey();
     $fkTag->setForeignTableCommonName($this->tagTable->getCommonName());
     $fkTag->setForeignSchemaName($this->tagTable->getSchema());
     $fkTag->setOnDelete(ForeignKey::CASCADE);
     $fkTag->setOnUpdate(ForeignKey::CASCADE);
     $tagColumn = $this->tagTable->getColumn('id');
     $fkTag->addReference($tagFkColumn->getName(), $tagColumn->getName());
     $this->taggingTable->addForeignKey($fkTag);
     $fkObj = new ForeignKey();
     $fkObj->setForeignTableCommonName($this->getTable()->getCommonName());
     $fkObj->setForeignSchemaName($this->getTable()->getSchema());
     $fkObj->setOnDelete(ForeignKey::CASCADE);
     $fkObj->setOnUpdate(ForeignKey::CASCADE);
     foreach ($pks as $column) {
         $fkObj->addReference($objFkColumn->getName(), $column->getName());
     }
     $this->taggingTable->addForeignKey($fkObj);
 }
Example #2
0
 protected function buildDescription()
 {
     if ($this->foreignTable === null) {
         throw new \yentu\exceptions\DatabaseManipulatorException("No references defined for foreign key {$this->name}");
     }
     return array('columns' => $this->columns, 'table' => $this->table->getName(), 'schema' => $this->table->getSchema()->getName(), 'foreign_columns' => $this->foreignColumns, 'foreign_table' => $this->foreignTable->getName(), 'foreign_schema' => $this->foreignTable->getSchema()->getName(), 'name' => $this->name, 'on_delete' => $this->onDelete, 'on_update' => $this->onUpdate);
 }
 /**
  * @param $table
  * @param $which
  * @return string
  */
 private static function _getClassForTable(Table $table, $which)
 {
     $id = $table->getSchema() . $table->getName();
     return isset(self::$_tableClassMap[$id]) && isset(self::$_tableClassMap[$id][$which]) ? self::$_tableClassMap[$id][$which] : self::$_tableClassMap[self::ALL_TABLES][$which];
 }
 /**
  * Returns the Name of the schema the foreign key is in
  */
 public function getSchemaName()
 {
     return $this->parentTable->getSchema();
 }