3
3
namespace LaravelDoctrine \Fluent \Builders \Overrides ;
4
4
5
5
use Doctrine \ORM \Mapping \Builder \ClassMetadataBuilder ;
6
- use Doctrine \ORM \Mapping \ClassMetadataInfo ;
6
+ use Doctrine \ORM \Mapping \ClassMetadata ;
7
7
use Doctrine \ORM \Mapping \NamingStrategy ;
8
8
use InvalidArgumentException ;
9
9
use LaravelDoctrine \Fluent \Buildable ;
10
+ use LaravelDoctrine \Fluent \Relations \AssociationCache ;
10
11
use LaravelDoctrine \Fluent \Relations \ManyToMany ;
11
12
use LaravelDoctrine \Fluent \Relations \ManyToOne ;
12
13
use LaravelDoctrine \Fluent \Relations \Relation ;
@@ -37,8 +38,8 @@ class AssociationOverride implements Buildable
37
38
* @var array
38
39
*/
39
40
protected $ relations = [
40
- ClassMetadataInfo ::MANY_TO_ONE => ManyToOne::class,
41
- ClassMetadataInfo ::MANY_TO_MANY => ManyToMany::class,
41
+ ClassMetadata ::MANY_TO_ONE => ManyToOne::class,
42
+ ClassMetadata ::MANY_TO_MANY => ManyToMany::class,
42
43
];
43
44
44
45
/**
@@ -95,7 +96,9 @@ public function build()
95
96
throw new InvalidArgumentException ('The callback should return an instance of ' .Relation::class);
96
97
}
97
98
98
- $ association ->build ();
99
+ $ association instanceof AssociationCache ?
100
+ $ association ->build ($ source ['targetEntity ' ]) :
101
+ $ association ->build ();
99
102
100
103
$ target = $ this ->convertToMappingArray ($ builder );
101
104
@@ -104,8 +107,8 @@ public function build()
104
107
// ManyToMany mappings
105
108
if ($ this ->hasJoinTable ($ target )) {
106
109
$ overrideMapping ['joinTable ' ] = $ this ->mapJoinTable (
107
- $ target ['joinTable ' ],
108
- $ source ['joinTable ' ]
110
+ ( array ) $ target ['joinTable ' ],
111
+ ( array ) $ source ['joinTable ' ]
109
112
);
110
113
}
111
114
@@ -134,7 +137,10 @@ protected function convertToMappingArray(ClassMetadataBuilder $builder)
134
137
{
135
138
$ metadata = $ builder ->getClassMetadata ();
136
139
137
- return $ metadata ->getAssociationMapping ($ this ->name );
140
+ $ associationMappingArray = (array ) $ metadata ->getAssociationMapping ($ this ->name );
141
+ $ associationMappingArray ['type ' ] = $ metadata ->getAssociationMapping ($ this ->name )->type ();
142
+
143
+ return $ associationMappingArray ;
138
144
}
139
145
140
146
/**
@@ -143,7 +149,7 @@ protected function convertToMappingArray(ClassMetadataBuilder $builder)
143
149
protected function newClassMetadataBuilder ()
144
150
{
145
151
return new ClassMetadataBuilder (
146
- new ClassMetadataInfo ($ this ->builder ->getClassMetadata ()->name )
152
+ new ClassMetadata ($ this ->builder ->getClassMetadata ()->name )
147
153
);
148
154
}
149
155
@@ -205,7 +211,7 @@ protected function mapJoinColumns(array $target = [], array $source = [])
205
211
$ joinColumns = [];
206
212
foreach ($ target as $ index => $ joinColumn ) {
207
213
if (isset ($ source [$ index ])) {
208
- $ diff = array_diff ($ joinColumn , $ source [$ index ]);
214
+ $ diff = array_diff (( array ) $ joinColumn , ( array ) $ source [$ index ]);
209
215
210
216
if (!empty ($ diff )) {
211
217
$ joinColumns [] = $ diff ;
0 commit comments