32 if (isset($this->model))
41 return $this->metas[
'#tableName'];
45 $table = $this->metas[
'#tableName'];
46 $primaryKeys = $this->metas[
'#primaryKeys'];
48 $nullables = $this->metas[
'#nullable'];
49 $fieldTypes = $this->metas[
'#fieldTypes'];
50 $manyToOnes = $this->metas[
'#manyToOne'];
52 $this->
generatePks($generator, $primaryKeys, $table, $fieldTypes, $nullables);
54 $serializables = \array_unique(\array_merge($serializables, $this->fkFieldsToAdd));
55 $fieldTypes = \array_merge($fieldTypes, $this->fkFieldTypesToAdd);
58 foreach ($this->fkFieldsToAdd as $fkField) {
59 $generator->
addKey($table, [
66 $notSerializable = $this->metas[
'#notSerializable'];
67 $fieldNames = $this->metas[
'#fieldNames'];
68 return \array_diff($fieldNames, $notSerializable);
72 if (isset($this->metas[
'#manyToMany'])) {
73 $manyToManys = $this->metas[
'#manyToMany'];
74 foreach ($manyToManys as $member => $manyToMany) {
75 if (isset($this->metas[
'#joinTable'][$member])) {
76 $annotJoinTable = $this->metas[
'#joinTable'][$member];
77 $generator->
addManyToMany($annotJoinTable, $manyToMany[
'targetEntity']);
84 $nullables = $this->metas[
'#nullable'];
85 $fieldTypes = $this->metas[
'#fieldTypes'];
90 if(\is_array($primaryKeys)) {
91 $generator->
addKey($table, $primaryKeys);
92 if (\count($primaryKeys) === 1 && $generator->
isInt($fieldTypes[$fpk=\current($primaryKeys)])) {
99 $fieldsAttributes = [];
100 foreach ($serializables as $field) {
103 return $fieldsAttributes;
111 $nullable =
'NOT NULL';
112 if (\array_search($field, $nullables) !==
false) {
117 'type' => $fieldTypes[$field]??DbTypes::DEFAULT_TYPE,
124 if ($fieldAnnot !==
null) {
125 $annotationArray = $fieldAnnot[1];
128 $fkFieldName = $fieldAnnot[0];
129 $this->fkFieldsToAdd[] = $fkFieldName;
130 $this->fkFieldTypesToAdd[$fkFieldName] =
OrmUtils::getFieldType($annotationArray[
'className'], $referencesFieldName);
131 $generator->
addForeignKey($tableName, $fkFieldName, $referencesTableName, $referencesFieldName);
136 foreach ($manyToOnes as $member) {
createTable($name, $fieldsAttributes, $attributes=[])
addAutoInc($tableName, $fieldName, $fieldInfos, $value=1)
generateField($fieldAttributes, $forPk=false)
addManyToMany($jointableInfos, $targetEntity)
addKey($tableName, $fieldNames, $type='PRIMARY')
addForeignKey($tableName, $fkFieldName, $referencesTableName, $referencesFieldName, $fkName=null, $onDelete='CASCADE', $onUpdate='NO ACTION')
Object/relational mapping utilities.
static getTableName($class)
static getModelMetadata($className)
addPrimaryKeys(DbGenerator $generator, array $primayKeys)
generateSQL(DbGenerator $generator)
scanManyToManys(DbGenerator $generator)
_generateFieldAttributes($field, $nullables, $fieldTypes)
getFieldAttributes(DbGenerator $generator, $field, $nullables, $fieldTypes, $forPk=false)
generateForeignKey(DbGenerator $generator, $tableName, $member)
generatePks(DbGenerator $generator, $primaryKeys, $table, $fieldTypes, $nullables)
generateFieldsAttributes($serializables, $fieldTypes, $nullables)
generateForeignKeys(DbGenerator $generator, $manyToOnes, $tableName)
static getFieldType($className, $field)
static getFirstKey($class)
static getMemberJoinColumns($instance, $member, $metaDatas=NULL)