@@ 2308-2328 (lines=21) @@ | ||
2305 | * @param object $document |
|
2306 | * @param array $visited |
|
2307 | */ |
|
2308 | private function cascadeDetach($document, array &$visited) |
|
2309 | { |
|
2310 | $class = $this->dm->getClassMetadata(get_class($document)); |
|
2311 | foreach ($class->fieldMappings as $mapping) { |
|
2312 | if ( ! $mapping['isCascadeDetach']) { |
|
2313 | continue; |
|
2314 | } |
|
2315 | $relatedDocuments = $class->reflFields[$mapping['fieldName']]->getValue($document); |
|
2316 | if (($relatedDocuments instanceof Collection || is_array($relatedDocuments))) { |
|
2317 | if ($relatedDocuments instanceof PersistentCollectionInterface) { |
|
2318 | // Unwrap so that foreach() does not initialize |
|
2319 | $relatedDocuments = $relatedDocuments->unwrap(); |
|
2320 | } |
|
2321 | foreach ($relatedDocuments as $relatedDocument) { |
|
2322 | $this->doDetach($relatedDocument, $visited); |
|
2323 | } |
|
2324 | } elseif ($relatedDocuments !== null) { |
|
2325 | $this->doDetach($relatedDocuments, $visited); |
|
2326 | } |
|
2327 | } |
|
2328 | } |
|
2329 | /** |
|
2330 | * Cascades a merge operation to associated documents. |
|
2331 | * |
|
@@ 2428-2449 (lines=22) @@ | ||
2425 | * @param object $document |
|
2426 | * @param array $visited |
|
2427 | */ |
|
2428 | private function cascadeRemove($document, array &$visited) |
|
2429 | { |
|
2430 | $class = $this->dm->getClassMetadata(get_class($document)); |
|
2431 | foreach ($class->fieldMappings as $mapping) { |
|
2432 | if ( ! $mapping['isCascadeRemove']) { |
|
2433 | continue; |
|
2434 | } |
|
2435 | if ($document instanceof Proxy && ! $document->__isInitialized__) { |
|
2436 | $document->__load(); |
|
2437 | } |
|
2438 | ||
2439 | $relatedDocuments = $class->reflFields[$mapping['fieldName']]->getValue($document); |
|
2440 | if (($relatedDocuments instanceof Collection || is_array($relatedDocuments))) { |
|
2441 | // If its a PersistentCollection initialization is intended! No unwrap! |
|
2442 | foreach ($relatedDocuments as $relatedDocument) { |
|
2443 | $this->doRemove($relatedDocument, $visited); |
|
2444 | } |
|
2445 | } elseif ($relatedDocuments !== null) { |
|
2446 | $this->doRemove($relatedDocuments, $visited); |
|
2447 | } |
|
2448 | } |
|
2449 | } |
|
2450 | ||
2451 | /** |
|
2452 | * Acquire a lock on the given document. |