@@ -106,20 +106,22 @@ public function getClasses(): array
106
106
private function addRelation (mixed $ fieldDefinition , Relation $ relation , ClassDefinition $ classDefinition ): void
107
107
{
108
108
// TODO Check cases where $fieldDefinition->getClasses() has more than one item
109
- /** @var string $class */
110
- $ class = $ fieldDefinition ->getClasses ()[0 ]['classes ' ];
111
- $ relation ->setSourceType ($ classDefinition ->getName () ?? self ::UNKNOWN )
112
- ->setTargetType ($ class )
113
- ->setSourceRolename ($ fieldDefinition ->getTitle ())
114
- ->setMinimum ($ fieldDefinition ->getMandatory () ? 1 : 0 );
115
-
116
- $ relationsKey = sprintf ('%s.%s - %s ' , $ relation ->getSourceType (), $ fieldDefinition ->getName (), $ relation ->getTargetType ());
117
-
118
- // if relation already exists it must be bidirectional
119
- if (\array_key_exists ($ relationsKey , $ this ->relations )) {
120
- $ relation ->setBidirectional (true );
109
+ if (!empty ($ fieldDefinition ->getClasses ())) {
110
+ /** @var string $class */
111
+ $ class = $ fieldDefinition ->getClasses ()[0 ]['classes ' ];
112
+ $ relation ->setSourceType ($ classDefinition ->getName () ?? self ::UNKNOWN )
113
+ ->setTargetType ($ class )
114
+ ->setSourceRolename ($ fieldDefinition ->getTitle ())
115
+ ->setMinimum ($ fieldDefinition ->getMandatory () ? 1 : 0 );
116
+
117
+ $ relationsKey = sprintf ('%s.%s - %s ' , $ relation ->getSourceType (), $ fieldDefinition ->getName (), $ relation ->getTargetType ());
118
+
119
+ // if relation already exists it must be bidirectional
120
+ if (\array_key_exists ($ relationsKey , $ this ->relations )) {
121
+ $ relation ->setBidirectional (true );
122
+ }
123
+ $ this ->relations [$ relationsKey ] = $ relation ;
121
124
}
122
- $ this ->relations [$ relationsKey ] = $ relation ;
123
125
}
124
126
125
127
private function addReverseRelation (ClassDefinition \Data \ReverseObjectRelation $ fieldDefinition , Relation $ relation , ClassDefinition $ classDefinition ): void
0 commit comments