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


PHP Table::hasForeignKeys方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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


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