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