33namespace LaravelDoctrine \Fluent \Builders \Overrides ;
44
55use Doctrine \ORM \Mapping \Builder \ClassMetadataBuilder ;
6- use Doctrine \ORM \Mapping \ClassMetadataInfo ;
6+ use Doctrine \ORM \Mapping \ClassMetadata ;
77use Doctrine \ORM \Mapping \NamingStrategy ;
88use InvalidArgumentException ;
99use LaravelDoctrine \Fluent \Buildable ;
10+ use LaravelDoctrine \Fluent \Relations \AssociationCache ;
1011use LaravelDoctrine \Fluent \Relations \ManyToMany ;
1112use LaravelDoctrine \Fluent \Relations \ManyToOne ;
1213use LaravelDoctrine \Fluent \Relations \Relation ;
@@ -37,8 +38,8 @@ class AssociationOverride implements Buildable
3738 * @var array
3839 */
3940 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,
4243 ];
4344
4445 /**
@@ -95,7 +96,9 @@ public function build()
9596 throw new InvalidArgumentException ('The callback should return an instance of ' .Relation::class);
9697 }
9798
98- $ association ->build ();
99+ $ association instanceof AssociationCache ?
100+ $ association ->build ($ source ['targetEntity ' ]) :
101+ $ association ->build ();
99102
100103 $ target = $ this ->convertToMappingArray ($ builder );
101104
@@ -104,8 +107,8 @@ public function build()
104107 // ManyToMany mappings
105108 if ($ this ->hasJoinTable ($ target )) {
106109 $ overrideMapping ['joinTable ' ] = $ this ->mapJoinTable (
107- $ target ['joinTable ' ],
108- $ source ['joinTable ' ]
110+ ( array ) $ target ['joinTable ' ],
111+ ( array ) $ source ['joinTable ' ]
109112 );
110113 }
111114
@@ -134,7 +137,10 @@ protected function convertToMappingArray(ClassMetadataBuilder $builder)
134137 {
135138 $ metadata = $ builder ->getClassMetadata ();
136139
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 ;
138144 }
139145
140146 /**
@@ -143,7 +149,7 @@ protected function convertToMappingArray(ClassMetadataBuilder $builder)
143149 protected function newClassMetadataBuilder ()
144150 {
145151 return new ClassMetadataBuilder (
146- new ClassMetadataInfo ($ this ->builder ->getClassMetadata ()->name )
152+ new ClassMetadata ($ this ->builder ->getClassMetadata ()->name )
147153 );
148154 }
149155
@@ -205,7 +211,7 @@ protected function mapJoinColumns(array $target = [], array $source = [])
205211 $ joinColumns = [];
206212 foreach ($ target as $ index => $ joinColumn ) {
207213 if (isset ($ source [$ index ])) {
208- $ diff = array_diff ($ joinColumn , $ source [$ index ]);
214+ $ diff = array_diff (( array ) $ joinColumn , ( array ) $ source [$ index ]);
209215
210216 if (!empty ($ diff )) {
211217 $ joinColumns [] = $ diff ;
0 commit comments