@@ 2284-2304 (lines=21) @@ | ||
2281 | * @param object $document |
|
2282 | * @param array $visited |
|
2283 | */ |
|
2284 | private function cascadeDetach($document, array &$visited) |
|
2285 | { |
|
2286 | $class = $this->dm->getClassMetadata(get_class($document)); |
|
2287 | foreach ($class->fieldMappings as $mapping) { |
|
2288 | if ( ! $mapping['isCascadeDetach']) { |
|
2289 | continue; |
|
2290 | } |
|
2291 | $relatedDocuments = $class->reflFields[$mapping['fieldName']]->getValue($document); |
|
2292 | if (($relatedDocuments instanceof Collection || is_array($relatedDocuments))) { |
|
2293 | if ($relatedDocuments instanceof PersistentCollection) { |
|
2294 | // Unwrap so that foreach() does not initialize |
|
2295 | $relatedDocuments = $relatedDocuments->unwrap(); |
|
2296 | } |
|
2297 | foreach ($relatedDocuments as $relatedDocument) { |
|
2298 | $this->doDetach($relatedDocument, $visited); |
|
2299 | } |
|
2300 | } elseif ($relatedDocuments !== null) { |
|
2301 | $this->doDetach($relatedDocuments, $visited); |
|
2302 | } |
|
2303 | } |
|
2304 | } |
|
2305 | /** |
|
2306 | * Cascades a merge operation to associated documents. |
|
2307 | * |
|
@@ 2404-2425 (lines=22) @@ | ||
2401 | * @param object $document |
|
2402 | * @param array $visited |
|
2403 | */ |
|
2404 | private function cascadeRemove($document, array &$visited) |
|
2405 | { |
|
2406 | $class = $this->dm->getClassMetadata(get_class($document)); |
|
2407 | foreach ($class->fieldMappings as $mapping) { |
|
2408 | if ( ! $mapping['isCascadeRemove']) { |
|
2409 | continue; |
|
2410 | } |
|
2411 | if ($document instanceof Proxy && ! $document->__isInitialized__) { |
|
2412 | $document->__load(); |
|
2413 | } |
|
2414 | ||
2415 | $relatedDocuments = $class->reflFields[$mapping['fieldName']]->getValue($document); |
|
2416 | if (($relatedDocuments instanceof Collection || is_array($relatedDocuments))) { |
|
2417 | // If its a PersistentCollection initialization is intended! No unwrap! |
|
2418 | foreach ($relatedDocuments as $relatedDocument) { |
|
2419 | $this->doRemove($relatedDocument, $visited); |
|
2420 | } |
|
2421 | } elseif ($relatedDocuments !== null) { |
|
2422 | $this->doRemove($relatedDocuments, $visited); |
|
2423 | } |
|
2424 | } |
|
2425 | } |
|
2426 | ||
2427 | /** |
|
2428 | * Acquire a lock on the given document. |