@@ -200,21 +200,29 @@ private function insertElements(PersistentCollectionInterface $coll, array $opti
200200 }
201201
202202 $ mapping = $ coll ->getMapping ();
203- list ($ propertyPath , $ parent ) = $ this ->getPathAndParent ($ coll );
204203
205- $ pb = $ this ->pb ;
204+ switch ($ mapping ['strategy ' ]) {
205+ case ClassMetadataInfo::STORAGE_STRATEGY_PUSH_ALL :
206+ $ operator = 'push ' ;
207+ break ;
208+
209+ case ClassMetadataInfo::STORAGE_STRATEGY_ADD_TO_SET :
210+ $ operator = 'addToSet ' ;
211+ break ;
212+
213+ default :
214+ throw new \LogicException ("Invalid strategy {$ mapping ['strategy ' ]} given for insertElements " );
215+ }
216+
217+ list ($ propertyPath , $ parent ) = $ this ->getPathAndParent ($ coll );
206218
207219 $ callback = isset ($ mapping ['embedded ' ])
208- ? function ($ v ) use ($ pb , $ mapping ) { return $ pb ->prepareEmbeddedDocumentValue ($ mapping , $ v ); }
209- : function ($ v ) use ($ pb , $ mapping ) { return $ pb ->prepareReferencedDocumentValue ($ mapping , $ v ); };
220+ ? function ($ v ) use ($ mapping ) { return $ this -> pb ->prepareEmbeddedDocumentValue ($ mapping , $ v ); }
221+ : function ($ v ) use ($ mapping ) { return $ this -> pb ->prepareReferencedDocumentValue ($ mapping , $ v ); };
210222
211223 $ value = array_values (array_map ($ callback , $ insertDiff ));
212224
213- if ($ mapping ['strategy ' ] === ClassMetadataInfo::STORAGE_STRATEGY_ADD_TO_SET ) {
214- $ value = array ('$each ' => $ value );
215- }
216-
217- $ query = array ('$ ' . $ mapping ['strategy ' ] => array ($ propertyPath => $ value ));
225+ $ query = ['$ ' . $ operator => [$ propertyPath => ['$each ' => $ value ]]];
218226
219227 $ this ->executeQuery ($ parent , $ query , $ options );
220228 }
0 commit comments