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


PHP ForeignKey::model方法代码示例

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


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

示例1: actionUpdate

 public function actionUpdate()
 {
     $isSubmitted = false;
     $sql = false;
     $foreignKey = ForeignKey::model()->findBySql('SELECT * FROM KEY_COLUMN_USAGE ' . 'WHERE TABLE_SCHEMA = :tableSchema ' . 'AND TABLE_NAME = :tableName ' . 'AND COLUMN_NAME = :columnName ' . 'AND REFERENCED_TABLE_SCHEMA IS NOT NULL', array('tableSchema' => $this->schema, 'tableName' => $this->table, 'columnName' => $this->column));
     if (!$foreignKey) {
         $foreignKey = new ForeignKey();
         $foreignKey->TABLE_SCHEMA = $this->schema;
         $foreignKey->TABLE_NAME = $this->table;
         $foreignKey->COLUMN_NAME = $this->column;
     }
     if (isset($_POST['ForeignKey'])) {
         $foreignKey->attributes = $_POST['ForeignKey'];
         if ($foreignKey->getReferences() && ($sql = $foreignKey->save())) {
             $isSubmitted = true;
         } elseif (!$foreignKey->getReferences() && ($sql = $foreignKey->delete())) {
             $isSubmitted = true;
         }
     }
     CHtml::generateRandomIdPrefix();
     // Column data
     $columns = array('' => '');
     $tables = Table::model()->findAllByAttributes(array('TABLE_SCHEMA' => $this->schema));
     foreach ($tables as $table) {
         if (StorageEngine::check($table->ENGINE, StorageEngine::SUPPORTS_FOREIGN_KEYS)) {
             $columns[$table->TABLE_NAME] = array();
             foreach ($table->columns as $column) {
                 $columns[$table->TABLE_NAME][$this->schema . '.' . $table->TABLE_NAME . '.' . $column->COLUMN_NAME] = $column->COLUMN_NAME;
             }
         }
     }
     // "On-Actions"
     $onActions = array('' => '', 'CASCADE' => 'CASCADE', 'SET NULL' => 'SET NULL', 'NO ACTION' => 'NO ACTION', 'RESTRICT' => 'RESTRICT');
     $this->render('form', array('foreignKey' => $foreignKey, 'columns' => $columns, 'onActions' => $onActions, 'sql' => $sql, 'isSubmitted' => $isSubmitted));
 }
开发者ID:cebe,项目名称:chive,代码行数:35,代码来源:ForeignKeyController.php

示例2: actionStructure

 /**
  * Shows the table structure
  */
 public function actionStructure()
 {
     $table = $this->loadTable();
     if (!$table instanceof Table) {
         $response = new AjaxResponse();
         $response->addNotification("error", Yii::t("core", "tableLoadErrorTitle", array("{table}" => $this->table)), Yii::t("core", "tableLoadErrorMessage", array("{table}" => $this->table)));
         $response->executeJavaScript("sideBar.loadTables(schema)");
         $this->sendJSON($response);
     }
     // Constraints
     if (StorageEngine::check($table->ENGINE, StorageEngine::SUPPORTS_FOREIGN_KEYS)) {
         $foreignKeys = array();
         $sql = 'SELECT * FROM KEY_COLUMN_USAGE ' . 'WHERE TABLE_SCHEMA = :tableSchema ' . 'AND TABLE_NAME = :tableName ' . 'AND REFERENCED_TABLE_SCHEMA IS NOT NULL';
         $table->foreignKeys = ForeignKey::model()->findAllBySql($sql, array('tableSchema' => $table->TABLE_SCHEMA, 'tableName' => $table->TABLE_NAME));
         foreach ($table->foreignKeys as $key) {
             $foreignKeys[] = $key->COLUMN_NAME;
         }
     } else {
         $foreignKeys = false;
     }
     // Indices
     $sql = 'SELECT * FROM STATISTICS ' . 'WHERE TABLE_SCHEMA = :tableSchema ' . 'AND TABLE_NAME = :tableName ' . 'GROUP BY INDEX_NAME ' . 'ORDER BY INDEX_NAME = \'PRIMARY\' DESC, INDEX_NAME';
     $table->indices = Index::model()->findAllBySql($sql, array('tableSchema' => $table->TABLE_SCHEMA, 'tableName' => $table->TABLE_NAME));
     foreach ($table->indices as $index) {
         $index->columns = IndexColumn::model()->findAllByAttributes(array('TABLE_SCHEMA' => $table->TABLE_SCHEMA, 'TABLE_NAME' => $table->TABLE_NAME, 'INDEX_NAME' => $index->INDEX_NAME));
     }
     // Indices (seperate for each column)
     $indicesRaw = Index::model()->findAllByAttributes(array('TABLE_SCHEMA' => $table->TABLE_SCHEMA, 'TABLE_NAME' => $table->TABLE_NAME));
     // Triggers
     $table->triggers = Trigger::model()->findAllByAttributes(array('EVENT_OBJECT_SCHEMA' => $table->TABLE_SCHEMA, 'EVENT_OBJECT_TABLE' => $table->TABLE_NAME));
     $this->render('structure', array('table' => $table, 'canAlter' => Yii::app()->user->privileges->checkTable($table->TABLE_SCHEMA, $table->TABLE_NAME, 'ALTER'), 'foreignKeys' => $foreignKeys, 'indicesRaw' => $indicesRaw));
 }
开发者ID:cebe,项目名称:chive,代码行数:35,代码来源:TableController.php

示例3: testInsertNotNew

 /**
  * tries to insert a foreignkey which is not new
  * @expectedException CDbException
  */
 public function testInsertNotNew()
 {
     $fk = ForeignKey::model()->findBySql('SELECT * FROM KEY_COLUMN_USAGE ' . 'WHERE TABLE_SCHEMA = :tableSchema ' . 'AND TABLE_NAME = :tableName ' . 'AND COLUMN_NAME = :columnName ' . 'AND REFERENCED_TABLE_SCHEMA IS NOT NULL', array('tableSchema' => 'tabletest', 'tableName' => 'product_order', 'columnName' => 'customer_id'));
     $fk->insert();
 }
开发者ID:cebe,项目名称:chive,代码行数:9,代码来源:ForeignKeyTest.php


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