Example #1
0
 public function getReferencingKeyNames(Table $otherTable, $otherColumnName = null)
 {
     $otherInflectedColumnName = $this->inflectInputColumnName($otherColumnName);
     $refCols = $otherTable->getReferenceColumns();
     foreach ($refCols as $refColName => $refCol) {
         $ref = $refCol->getReference();
         if ($ref->belongsTo($this) && (!$otherColumnName || $otherInflectedColumnName === $refColName)) {
             $thisKey = $this->inflectOutputColumnName($ref->getName());
             $otherKey = $this->inflectOutputColumnName($refColName);
             return [$thisKey, $otherKey];
         }
     }
     throw new \Exception("Failed to get referencing column names: No reference from {$otherTable} to {$this} found");
 }
Example #2
0
 public function addManyOne(Table $table, Table $glueTable, Row $row, $columnName = null, $otherColumnName = null)
 {
     list($thisKey, $thisGlueKey) = $this->getTable()->getReferenceKeyNames($glueTable, $columnName);
     list($otherKey, $otherGlueKey) = $table->getReferenceKeyNames($glueTable, $otherColumnName);
     if (!$table->equals($row->getTable())) {
         throw new Exception("Failed to addManyOne( {$table}, row ): Passed row's table doesnt match expected table {$table}");
     }
     if (!isset($this->_data[$thisKey])) {
         throw new Exception("Failed to addManyOne: Row has no {$thisKey} value");
     }
     if (!isset($row->_data[$otherKey])) {
         throw new Exception("Failed to addManyOne: Row has no {$otherKey} value");
     }
     return $glueTable->insert([$thisGlueKey => $this->_data[$thisKey], $otherGlueKey => $this->_data[$otherKey]]);
 }
Example #3
0
 public function removeTable(Table $table)
 {
     /* It's important that we drop all CONSTRAINTs first, so we iterate the columns and save them without a reference (triggers saveColumn()) */
     /* We also need to drop all CONSTRAINTs, that reference THIS table. This will take a lot of performance right now */
     //TODO: OPTIMIZE PERFORMANCE!!!
     foreach ($table->getColumns()->loadAll() as $col) {
         $this->dropConstraint($col);
         $this->dropForeignConstraints($col);
     }
     $name = $this->quoteName($table->getDatabase(), $table);
     $this->query("DROP TABLE {$name}");
     return $this;
 }