@@ -80,9 +80,9 @@ public function markTracked(object $entity, Collection $collection): bool
8080
8181 public function persist (object $ object , Collection $ onCollection ): object
8282 {
83- $ next = $ onCollection ->next ;
84- if ($ onCollection instanceof Filtered && $ next !== null ) {
85- $ this ->persist ($ object , $ next );
83+ $ connectsTo = $ onCollection ->connectsTo ;
84+ if ($ onCollection instanceof Filtered && $ connectsTo !== null ) {
85+ $ this ->persist ($ object , $ connectsTo );
8686
8787 return $ object ;
8888 }
@@ -103,6 +103,7 @@ public function persist(object $object, Collection $onCollection): object
103103
104104 $ this ->pending [$ object ] = 'insert ' ;
105105 $ this ->markTracked ($ object , $ onCollection );
106+ $ this ->registerInIdentityMap ($ object , $ onCollection );
106107
107108 return $ object ;
108109 }
@@ -123,21 +124,9 @@ public function isTracked(object $entity): bool
123124 return $ this ->tracked ->offsetExists ($ entity );
124125 }
125126
126- public function replaceTracked (object $ old , object $ new , Collection $ onCollection ): void
127- {
128- $ op = $ this ->pending [$ old ] ?? 'update ' ;
129- $ this ->tracked ->offsetUnset ($ old );
130- $ this ->pending ->offsetUnset ($ old );
131- $ this ->evictFromIdentityMap ($ old , $ onCollection );
132-
133- $ this ->markTracked ($ new , $ onCollection );
134- $ this ->registerInIdentityMap ($ new , $ onCollection );
135- $ this ->pending [$ new ] = $ op ;
136- }
137-
138127 public function registerCollection (string $ alias , Collection $ collection ): void
139128 {
140- $ collection ->mapper = $ this ;
129+ $ collection ->bindMapper ( $ this ) ;
141130 $ this ->collections [$ alias ] = $ collection ;
142131 }
143132
@@ -199,7 +188,7 @@ protected function evictFromIdentityMap(object $entity, Collection $coll): void
199188
200189 protected function findInIdentityMap (Collection $ collection ): object |null
201190 {
202- if ($ collection ->name === null || !is_scalar ($ collection ->condition ) || $ collection ->more ) {
191+ if ($ collection ->name === null || !is_scalar ($ collection ->condition ) || $ collection ->hasMore ) {
203192 return null ;
204193 }
205194
@@ -234,6 +223,8 @@ private function tryMergeWithIdentityMap(object $entity, Collection $coll): obje
234223 $ this ->entityFactory ->set ($ entity , $ idName , $ idValue );
235224 }
236225
226+ $ op = $ this ->pending [$ existing ] ?? 'update ' ;
227+
237228 if ($ this ->entityFactory ->isReadOnly ($ existing )) {
238229 $ merged = $ this ->entityFactory ->mergeEntities ($ existing , $ entity );
239230
@@ -245,7 +236,7 @@ private function tryMergeWithIdentityMap(object $entity, Collection $coll): obje
245236 $ this ->registerInIdentityMap ($ merged , $ coll );
246237 }
247238
248- $ this ->pending [$ merged ] = ' update ' ;
239+ $ this ->pending [$ merged ] = $ op ;
249240
250241 return $ merged ;
251242 }
@@ -258,7 +249,7 @@ private function tryMergeWithIdentityMap(object $entity, Collection $coll): obje
258249 $ this ->markTracked ($ existing , $ coll );
259250 }
260251
261- $ this ->pending [$ existing ] = ' update ' ;
252+ $ this ->pending [$ existing ] = $ op ;
262253
263254 return $ existing ;
264255 }
@@ -290,9 +281,8 @@ public function __get(string $name): Collection
290281 }
291282
292283 $ coll = new Collection ($ name );
293- $ coll ->mapper = $ this ;
294284
295- return $ coll ;
285+ return $ coll-> bindMapper ( $ this ) ;
296286 }
297287
298288 public function __isset (string $ alias ): bool
@@ -310,14 +300,10 @@ public function __call(string $name, array $arguments): Collection
310300 {
311301 if (isset ($ this ->collections [$ name ])) {
312302 $ collection = clone $ this ->collections [$ name ];
313- $ collection ->mapper = $ this ;
314303
315- return $ collection ->with (...$ arguments );
304+ return $ collection ->bindMapper ( $ this )-> with (...$ arguments );
316305 }
317306
318- $ collection = Collection::__callstatic ($ name , $ arguments );
319- $ collection ->mapper = $ this ;
320-
321- return $ collection ;
307+ return Collection::__callstatic ($ name , $ arguments )->bindMapper ($ this );
322308 }
323309}
0 commit comments