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