/** * @return string */ function masterColumn() { if (!isset($this->master_column)) { $this->master_column = 'id_' . Names::setToSingle($this->property->getAnnotation('foreign')->value); } return $this->master_column; }
/** * Create a table in database, which has no associated class, using fields names * * @param $mysqli mysqli * @param $table_name string * @param $column_names string[] * @return boolean * @todo mysqli context should contain sql builder (ie Select) in order to know if this was * an implicit link table. If then : only one unique index should be built */ private function createImplicitTable(mysqli $mysqli, $table_name, $column_names) { $only_ids = true; $table = new Table($table_name); $ids_index = new Index(); $ids_index->setType(Index::UNIQUE); $indexes = []; foreach ($column_names as $column_name) { $table->addColumn($column_name === 'id' ? Column::buildId() : Column::buildLink($column_name)); if (substr($column_name, 0, 3) === 'id_') { if ($mysqli instanceof Contextual_Mysqli && is_array($mysqli->context)) { $ids_index->addKey($column_name); $index = Index::buildLink($column_name); foreach ($mysqli->context as $context_class) { $id_context_property = 'id_' . Names::classToProperty(Names::setToSingle(Dao::storeNameOf($context_class))); $id_context_property_2 = 'id_' . Names::classToProperty(Names::setToSingle(Namespaces::shortClassName($context_class))); if (in_array($column_name, [$id_context_property, $id_context_property_2])) { $table->addForeignKey(Foreign_Key::buildLink($table_name, $column_name, $context_class)); break; } } $indexes[] = $index; } } else { $only_ids = false; } } if ($only_ids) { $table->addIndex($ids_index); } else { foreach ($indexes as $index) { $table->addIndex($index); } } $mysqli->query((new Create_Table($table))->build()); return true; }
/** * @param $property Reflection_Property * @return string[] */ private function defaultMap(Reflection_Property $property) { return [Names::setToSingle($property->getName())]; }