private function importConstraints(OrmProperty $property) { $name = $this->dbTable->getName() . '_' . $property->getName(); $fields = $property->getFields(); if ($property->isIdentifier()) { $this->dbTable->addConstraint(new DBPrimaryKeyConstraint($name . '_pk', $this->dbTable, $fields)); } else { if ($property->isUnique()) { $this->dbTable->addConstraint(new DBUniqueConstraint($name . '_uq', $this->dbTable, $fields)); } } $type = $property->getType(); if ($type instanceof AssociationPropertyType) { $this->dbTable->addConstraint(new DBOneToOneConstraint($name . '_fk', $this->dbTable, $fields, $this->dbSchema->getTable($property->getType()->getContainer()->getTable()), $property->getType()->getAssociationBreakAction())); } else { if ($type instanceof CompositePropertyType) { foreach ($type->getProperties($property) as $_property) { $this->importConstraints($_property); } } } if ($property->isQueryable()) { $this->dbTable->addIndex(new DBIndex($name . '_idx', $this->dbTable, $fields)); } }
/** * @return void */ private function importProperty() { if (!sizeof($this->ormProperty->getFields())) { // columnless properties are skipped return; } $columns = array_combine($this->ormProperty->getFields(), $this->ormProperty->getType()->getSqlTypes()); $dbColumns = array(); foreach ($columns as $name => $dbType) { $dbColumns[$name] = new DBColumn($name, $dbType); } $fields = array_keys($dbColumns); $this->dbTable->addColumns($dbColumns); if ($this->ormProperty->getType() instanceof AssociationPropertyType) { $this->dbTable->addConstraint(new DBOneToOneConstraint($fields, $this->dbSchema->getTable($this->ormProperty->getType()->getContainer()->getTable()), $this->ormProperty->getType()->getAssociationBreakAction())); } if ($this->ormProperty->isIdentifier()) { $this->dbTable->addConstraint(new DBPrimaryKeyConstraint($fields)); } else { if ($this->ormProperty->isUnique()) { $this->dbTable->addConstraint(new DBUniqueConstraint($fields)); } } }