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