当前位置: 首页>>代码示例>>PHP>>正文


PHP Table::getForeignKeys方法代码示例

本文整理汇总了PHP中Propel\Generator\Model\Table::getForeignKeys方法的典型用法代码示例。如果您正苦于以下问题:PHP Table::getForeignKeys方法的具体用法?PHP Table::getForeignKeys怎么用?PHP Table::getForeignKeys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Propel\Generator\Model\Table的用法示例。


在下文中一共展示了Table::getForeignKeys方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getOtherFks

 /**
  * Returns the list of other foreign keys starting on the same table.
  * Used in many-to-many relationships.
  *
  * @return ForeignKey[]
  */
 public function getOtherFks()
 {
     $fks = [];
     foreach ($this->parentTable->getForeignKeys() as $fk) {
         if ($fk !== $this) {
             $fks[] = $fk;
         }
     }
     return $fks;
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:16,代码来源:ForeignKey.php

示例2: getDropTableDDL

 public function getDropTableDDL(Table $table)
 {
     $ret = '';
     foreach ($table->getForeignKeys() as $fk) {
         $ret .= "\nIF EXISTS (SELECT 1 FROM sysobjects WHERE type ='RI' AND name='" . $fk->getName() . "')\n    ALTER TABLE " . $this->quoteIdentifier($table->getName()) . " DROP CONSTRAINT " . $this->quoteIdentifier($fk->getName()) . ";\n";
     }
     self::$dropCount++;
     $ret .= "\nIF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'U' AND name = '" . $table->getName() . "')\nBEGIN\n    DECLARE @reftable_" . self::$dropCount . " nvarchar(60), @constraintname_" . self::$dropCount . " nvarchar(60)\n    DECLARE refcursor CURSOR FOR\n    select reftables.name tablename, cons.name constraintname\n        from sysobjects tables,\n            sysobjects reftables,\n            sysobjects cons,\n            sysreferences ref\n        where tables.id = ref.rkeyid\n            and cons.id = ref.constid\n            and reftables.id = ref.fkeyid\n            and tables.name = '" . $table->getName() . "'\n    OPEN refcursor\n    FETCH NEXT from refcursor into @reftable_" . self::$dropCount . ", @constraintname_" . self::$dropCount . "\n    while @@FETCH_STATUS = 0\n    BEGIN\n        exec ('alter table '+@reftable_" . self::$dropCount . "+' drop constraint '+@constraintname_" . self::$dropCount . ")\n        FETCH NEXT from refcursor into @reftable_" . self::$dropCount . ", @constraintname_" . self::$dropCount . "\n    END\n    CLOSE refcursor\n    DEALLOCATE refcursor\n    DROP TABLE " . $this->quoteIdentifier($table->getName()) . "\nEND\n";
     return $ret;
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:10,代码来源:MssqlPlatform.php

示例3: testAddArrayForeignKey

 public function testAddArrayForeignKey()
 {
     $table = new Table('books');
     $table->setDatabase($this->getDatabaseMock('bookstore'));
     $fk = $table->addForeignKey(array('name' => 'fk_author_id', 'phpName' => 'Author', 'refPhpName' => 'Books', 'onDelete' => 'CASCADE', 'foreignTable' => 'authors'));
     $this->assertInstanceOf('Propel\\Generator\\Model\\ForeignKey', $fk);
     $this->assertCount(1, $table->getForeignKeys());
     $this->assertTrue($table->hasForeignKeys());
     $this->assertContains('authors', $table->getForeignTableNames());
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:10,代码来源:TableTest.php

示例4: checkTable

 /**
  * Unfortunately, SQLite does not support composite pks where one is AUTOINCREMENT,
  * so we have to flag both as NOT NULL and create a UNIQUE constraint.
  *
  * @param Table $table
  */
 public function checkTable(Table $table)
 {
     if ($table->hasForeignKeys()) {
         foreach ($table->getForeignKeys() as $fk) {
             if (!$fk->getForeignTable()->isUnique($fk->getForeignColumnObjects())) {
                 $unique = new Unique();
                 $unique->setColumns($fk->getForeignColumnObjects());
                 $fk->getForeignTable()->addUnique($unique);
             }
         }
     }
     if (count($pks = $table->getPrimaryKey()) > 1 && $table->hasAutoIncrementPrimaryKey()) {
         foreach ($pks as $pk) {
             //no pk can be NULL, as usual
             $pk->setNotNull(true);
             //in SQLite the column with the AUTOINCREMENT MUST be a primary key, too.
             if (!$pk->isAutoIncrement()) {
                 //for all other sub keys we remove it, since we create a UNIQUE constraint over all primary keys.
                 $pk->setPrimaryKey(false);
             }
         }
         //search if there is already a UNIQUE constraint over the primary keys
         $pkUniqueExist = false;
         foreach ($table->getUnices() as $unique) {
             $allPk = false;
             foreach ($unique->getColumns() as $columnName) {
                 $allPk &= $table->getColumn($columnName)->isPrimaryKey();
             }
             if ($allPk) {
                 //there's already a unique constraint with the composite pk
                 $pkUniqueExist = true;
                 break;
             }
         }
         //there is none, let's create it
         if (!$pkUniqueExist) {
             $unique = new Unique();
             foreach ($pks as $pk) {
                 $unique->addColumn($pk);
             }
             $table->addUnique($unique);
         }
     }
 }
开发者ID:a-melnichuk,项目名称:Movies-Demo,代码行数:50,代码来源:SqlitePlatform.php

示例5: normalizeTable

 /**
  * Normalizes a table for the current platform. Very important for the TableComparator to not
  * generate useless diffs.
  * Useful for checking needed definitions/structures. E.g. Unique Indexes for ForeignKey columns,
  * which the most Platforms requires but which is not always explicitly defined in the table model.
  *
  * @param Table $table The table object which gets modified.
  */
 public function normalizeTable(Table $table)
 {
     if ($table->hasForeignKeys()) {
         foreach ($table->getForeignKeys() as $fk) {
             if ($fk->getForeignTable() && !$fk->getForeignTable()->isUnique($fk->getForeignColumnObjects())) {
                 $unique = new Unique();
                 $unique->setColumns($fk->getForeignColumnObjects());
                 $fk->getForeignTable()->addUnique($unique);
             }
         }
     }
     if (!$this->supportsIndexSize() && $table->getIndices()) {
         // when the plafform does not support index sizes we reset it
         foreach ($table->getIndices() as $index) {
             $index->resetColumnsSize();
         }
     }
     foreach ($table->getColumns() as $column) {
         if ($column->getSize() && ($defaultSize = $this->getDefaultTypeSize($column->getType()))) {
             if (null === $column->getScale() && intval($column->getSize()) === $defaultSize) {
                 $column->setSize(null);
             }
         }
     }
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:33,代码来源:DefaultPlatform.php

示例6: getAddForeignKeysDDL

 /**
  * Builds the DDL SQL to add the foreign keys of a table.
  *
  * @param      Table $table
  * @return     string
  */
 public function getAddForeignKeysDDL(Table $table)
 {
     $ret = '';
     foreach ($table->getForeignKeys() as $fk) {
         $ret .= $this->getAddForeignKeyDDL($fk);
     }
     return $ret;
 }
开发者ID:rouffj,项目名称:Propel2,代码行数:14,代码来源:DefaultPlatform.php

示例7: appendTableNode

 /**
  * Appends the generated <table> XML node to its parent node.
  *
  * @param Table    $table      The Table model instance
  * @param \DOMNode $parentNode The parent DOMNode object
  */
 private function appendTableNode(Table $table, \DOMNode $parentNode)
 {
     $tableNode = $parentNode->appendChild($this->document->createElement('table'));
     $tableNode->setAttribute('name', $table->getCommonName());
     $database = $table->getDatabase();
     $schema = $table->getSchema();
     if ($schema && $schema !== $database->getSchema()) {
         $tableNode->setAttribute('schema', $schema);
     }
     if (IdMethod::NO_ID_METHOD !== ($idMethod = $table->getIdMethod())) {
         $tableNode->setAttribute('idMethod', $idMethod);
     }
     if ($phpName = $table->getPhpName()) {
         $tableNode->setAttribute('phpName', $phpName);
     }
     $package = $table->getPackage();
     if ($package && !$table->isPackageOverriden()) {
         $tableNode->setAttribute('package', $package);
     }
     if ($namespace = $table->getNamespace()) {
         $tableNode->setAttribute('namespace', $namespace);
     }
     if ($table->isSkipSql()) {
         $tableNode->setAttribute('skipSql', 'true');
     }
     if ($table->isAbstract()) {
         $tableNode->setAttribute('abstract', 'true');
     }
     if ($interface = $table->getInterface()) {
         $tableNode->setAttribute('interface', $interface);
     }
     if ($table->isCrossRef()) {
         $tableNode->setAttribute('isCrossRef', 'true');
     }
     $phpNamingMethod = $table->getPhpNamingMethod();
     if ($phpNamingMethod && $phpNamingMethod !== $database->getDefaultPhpNamingMethod()) {
         $tableNode->setAttribute('phpNamingMethod', $phpNamingMethod);
     }
     if ($baseClass = $table->getBaseClass()) {
         $tableNode->setAttribute('baseClass', $baseClass);
     }
     if ($baseQueryClass = $table->getBaseQueryClass()) {
         $tableNode->setAttribute('baseQueryClass', $baseQueryClass);
     }
     if ($table->isReadOnly()) {
         $tableNode->setAttribute('readOnly', 'true');
     }
     if ($table->isReloadOnInsert()) {
         $tableNode->setAttribute('reloadOnInsert', 'true');
     }
     if ($table->isReloadOnUpdate()) {
         $tableNode->setAttribute('reloadOnUpdate', 'true');
     }
     if (null !== ($referenceOnly = $table->isForReferenceOnly())) {
         $tableNode->setAttribute('forReferenceOnly', $referenceOnly ? 'true' : 'false');
     }
     if ($alias = $table->getAlias()) {
         $tableNode->setAttribute('alias', $alias);
     }
     if ($description = $table->getDescription()) {
         $tableNode->setAttribute('description', $description);
     }
     $defaultStringFormat = $table->getDefaultStringFormat();
     if (Table::DEFAULT_STRING_FORMAT !== $defaultStringFormat) {
         $tableNode->setAttribute('defaultStringFormat', $defaultStringFormat);
     }
     $defaultAccessorVisibility = $table->getDefaultAccessorVisibility();
     if ($defaultAccessorVisibility !== Table::VISIBILITY_PUBLIC) {
         $tableNode->setAttribute('defaultAccessorVisibility', $defaultAccessorVisibility);
     }
     $defaultMutatorVisibility = $table->getDefaultMutatorVisibility();
     if ($defaultMutatorVisibility !== Table::VISIBILITY_PUBLIC) {
         $tableNode->setAttribute('defaultMutatorVisibility', $defaultMutatorVisibility);
     }
     foreach ($table->getColumns() as $column) {
         $this->appendColumnNode($column, $tableNode);
     }
     foreach ($table->getForeignKeys() as $foreignKey) {
         $this->appendForeignKeyNode($foreignKey, $tableNode);
     }
     foreach ($table->getIdMethodParameters() as $parameter) {
         $this->appendIdMethodParameterNode($parameter, $tableNode);
     }
     foreach ($table->getIndices() as $index) {
         $this->appendIndexNode($index, $tableNode);
     }
     foreach ($table->getUnices() as $index) {
         $this->appendUniqueIndexNode($index, $tableNode);
     }
     foreach ($table->getVendorInformation() as $vendorInformation) {
         $this->appendVendorInformationNode($vendorInformation, $tableNode);
     }
     foreach ($table->getBehaviors() as $behavior) {
         $this->appendBehaviorNode($behavior, $tableNode);
//.........这里部分代码省略.........
开发者ID:SwissalpS,项目名称:Propel2,代码行数:101,代码来源:XmlDumper.php

示例8: normalizeTable

 /**
  * Normalizes a table for the current platform. Very important for the TableComparator to not
  * generate useless diffs.
  * Useful for checking needed definitions/structures. E.g. Unique Indexes for ForeignKey columns,
  * which the most Platforms requires but which is not always explicitly defined in the table model.
  *
  * @param Table $table The table object which gets modified.
  */
 public function normalizeTable(Table $table)
 {
     if ($table->hasForeignKeys()) {
         foreach ($table->getForeignKeys() as $fk) {
             if (!$fk->getForeignTable()->isUnique($fk->getForeignColumnObjects())) {
                 $unique = new Unique();
                 $unique->setColumns($fk->getForeignColumnObjects());
                 $fk->getForeignTable()->addUnique($unique);
             }
         }
     }
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:20,代码来源:DefaultPlatform.php

示例9: getAddForeignKeysDDL

 /**
  * {@inheritDoc}
  */
 public function getAddForeignKeysDDL(Table $table)
 {
     $ret = '';
     foreach ($table->getForeignKeys() as $fk) {
         //PostgreSQL requires the keys of the foreignTable of a foreignKeys to be unique.
         //check if there is already a unique constraint with exactly
         //the keys of the FK, if not define it.
         if ($fk->getForeignTable() && !$fk->getForeignTable()->isUnique($fk->getForeignColumnObjects())) {
             $unique = new Unique();
             $unique->setTable($fk->getForeignTable());
             $unique->setColumns($fk->getForeignColumnObjects());
             $ret .= $this->getAddIndexDDL($unique);
         }
         $ret .= $this->getAddForeignKeyDDL($fk);
     }
     return $ret;
 }
开发者ID:a-melnichuk,项目名称:Movies-Demo,代码行数:20,代码来源:PgsqlPlatform.php


注:本文中的Propel\Generator\Model\Table::getForeignKeys方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。