public function SetTable(Relational\ITable $Table) { if ($this->Table === $Table) { return; } $PrimaryKeyColumns = $Table->GetPrimaryKeyColumns(); if (count($PrimaryKeyColumns) === 0) { throw new Relational\RelationalException('Cannot generate keys for table %s without any primary key columns', $Table->GetName()); } $this->OnSetPrimaryKeyColumns($PrimaryKeyColumns); $this->PrimaryKeyColumns = $PrimaryKeyColumns; }
private function AddIdentityPrimaryKeyMapping(IDataPropertyColumnMapping $PropertyMapping) { //Infer primary key table $AllColumns = array_merge($PropertyMapping->GetPersistColumns(), $PropertyMapping->GetReviveColumns()); if ($this->PrimaryKeyTable === null) { $this->PrimaryKeyTable = reset($AllColumns)->GetTable(); } foreach ($AllColumns as $Column) { if (!$Column->GetTable()->Is($this->PrimaryKeyTable)) { throw new MappingException('Identity properties of %s cannot map across multiple tables: %s.%s does not belong to %s', $this->EntityType, $Column->GetTable()->GetName(), $Column->GetName(), $this->PrimaryKeyTable->GetName()); } } $this->IdentityPropertyPrimaryKeyMappings[] = $PropertyMapping; }
private function MakeForeignKey(Relational\ITable $Table, Map $ReferencedColumnMap) { return new ForeignKey($this->GetName() . '_' . $Table->GetName(), $ReferencedColumnMap, ForeignKeyMode::Cascade, ForeignKeyMode::Cascade); }
/** * Verifies a table is registered in this database. * * @param ITable $Table The table to verify * @throws \InvalidArgumentException If the table is not registered */ private function VerifyTable($Method, ITable $Table) { if (!$this->HasTable($Table->GetName())) { throw new InvalidTableException('Call to %s with supplied table %s does not belong to this database', $Method, $Table->GetName()); } }