Example #1
0
 /**
  * @param  string $tableName
  * @return \Dive\Table
  * @throws SchemaException
  */
 private function createTable($tableName)
 {
     $tableClass = $this->schema->getTableClass($tableName, true);
     $recordClass = $this->schema->getRecordClass($tableName);
     $fields = $this->schema->getTableFields($tableName);
     $relationsData = $this->schema->getTableRelations($tableName);
     $relations = $this->instantiateRelations($relationsData);
     $indexes = $this->schema->getTableIndexes($tableName);
     $this->initTableBehaviors($tableName);
     return new $tableClass($this, $tableName, $recordClass, $fields, $relations, $indexes);
 }
Example #2
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);
     }
 }
Example #3
0
 public function testAddTableField()
 {
     $this->schema->addTableField('user', 'saved_on', array('type' => 'datetime'));
     $fields = $this->schema->getTableFields('user');
     $this->assertArrayHasKey('saved_on', $fields);
 }