@@ 2087-2107 (lines=21) @@ | ||
2084 | * @param object $document |
|
2085 | * @param array $visited |
|
2086 | */ |
|
2087 | private function cascadeDetach($document, array &$visited) |
|
2088 | { |
|
2089 | $class = $this->dm->getClassMetadata(get_class($document)); |
|
2090 | foreach ($class->fieldMappings as $mapping) { |
|
2091 | if ( ! $mapping['isCascadeDetach']) { |
|
2092 | continue; |
|
2093 | } |
|
2094 | $relatedDocuments = $class->reflFields[$mapping['fieldName']]->getValue($document); |
|
2095 | if (($relatedDocuments instanceof Collection || is_array($relatedDocuments))) { |
|
2096 | if ($relatedDocuments instanceof PersistentCollectionInterface) { |
|
2097 | // Unwrap so that foreach() does not initialize |
|
2098 | $relatedDocuments = $relatedDocuments->unwrap(); |
|
2099 | } |
|
2100 | foreach ($relatedDocuments as $relatedDocument) { |
|
2101 | $this->doDetach($relatedDocument, $visited); |
|
2102 | } |
|
2103 | } elseif ($relatedDocuments !== null) { |
|
2104 | $this->doDetach($relatedDocuments, $visited); |
|
2105 | } |
|
2106 | } |
|
2107 | } |
|
2108 | /** |
|
2109 | * Cascades a merge operation to associated documents. |
|
2110 | * |
|
@@ 2202-2223 (lines=22) @@ | ||
2199 | * @param object $document |
|
2200 | * @param array $visited |
|
2201 | */ |
|
2202 | private function cascadeRemove($document, array &$visited) |
|
2203 | { |
|
2204 | $class = $this->dm->getClassMetadata(get_class($document)); |
|
2205 | foreach ($class->fieldMappings as $mapping) { |
|
2206 | if ( ! $mapping['isCascadeRemove']) { |
|
2207 | continue; |
|
2208 | } |
|
2209 | if ($document instanceof Proxy && ! $document->__isInitialized__) { |
|
2210 | $document->__load(); |
|
2211 | } |
|
2212 | ||
2213 | $relatedDocuments = $class->reflFields[$mapping['fieldName']]->getValue($document); |
|
2214 | if ($relatedDocuments instanceof Collection || is_array($relatedDocuments)) { |
|
2215 | // If its a PersistentCollection initialization is intended! No unwrap! |
|
2216 | foreach ($relatedDocuments as $relatedDocument) { |
|
2217 | $this->doRemove($relatedDocument, $visited); |
|
2218 | } |
|
2219 | } elseif ($relatedDocuments !== null) { |
|
2220 | $this->doRemove($relatedDocuments, $visited); |
|
2221 | } |
|
2222 | } |
|
2223 | } |
|
2224 | ||
2225 | /** |
|
2226 | * Acquire a lock on the given document. |