예제 #1
0
 /**
  * @param string $viewName
  * @return \Dive\Table
  * @throws SchemaException
  */
 private function createView($viewName)
 {
     $viewClass = $this->schema->getViewClass($viewName, true);
     $recordClass = $this->schema->getRecordClass($viewName);
     $fields = $this->schema->getViewFields($viewName);
     $relationsData = $this->schema->getTableRelations($viewName);
     $relations = $this->instantiateRelations($relationsData);
     return new $viewClass($this, $viewName, $recordClass, $fields, $relations);
 }
예제 #2
0
파일: SchemaTest.php 프로젝트: sigma-z/dive
 public function testAddRelation()
 {
     $this->schema->addTable('somewhere', array('id' => array('type' => 'integer')));
     $this->schema->addTable('somewhat', array('id' => array('type' => 'integer')));
     $relation = array('owningTable' => 'somewhere', 'owningField' => 'id', 'owningAlias' => 'Somewhat', 'refTable' => 'somewhat', 'refAlias' => 'Somewhere', 'refField' => 'id', 'type' => Relation::ONE_TO_ONE);
     $this->schema->addTableRelation('somewhere', 'id', $relation);
     $tableRelations = $this->schema->getTableRelations('somewhere');
     $expected = array('owning' => array('somewhere.id'), 'referenced' => array());
     $actual = array('owning' => array_keys($tableRelations['owning']), 'referenced' => array_keys($tableRelations['referenced']));
     $this->assertEquals($expected, $actual);
     $tableRelations = $this->schema->getTableRelations('somewhat');
     $expected = array('owning' => array(), 'referenced' => array('somewhere.id'));
     $actual = array('owning' => array_keys($tableRelations['owning']), 'referenced' => array_keys($tableRelations['referenced']));
     $this->assertEquals($expected, $actual);
 }
예제 #3
0
파일: Migration.php 프로젝트: sigma-z/dive
 /**
  * @param Schema $schema
  */
 public function importFromSchema(Schema $schema)
 {
     $this->columns = $schema->getTableFields($this->tableName);
     $this->indexes = $schema->getTableIndexes($this->tableName);
     $foreignKeys = $schema->getTableRelations($this->tableName);
     /** @var array[] $owningRelations */
     $owningRelations = $foreignKeys['owning'];
     foreach ($owningRelations as $definition) {
         $owningField = $definition['owningField'];
         $this->foreignKeys[$owningField] = array('refTable' => $definition['refTable'], 'refField' => $definition['refField'], 'onDelete' => isset($definition['onDelete']) ? $definition['onDelete'] : null, 'onUpdate' => isset($definition['onUpdate']) ? $definition['onUpdate'] : null);
     }
 }