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