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); }