Example #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);
 }
Example #2
0
 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);
 }
Example #3
0
 /**
  * @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);
     }
 }