@@ 2106-2126 (lines=21) @@ | ||
2103 | * @param object $document |
|
2104 | * @param array $visited |
|
2105 | */ |
|
2106 | private function cascadeDetach($document, array &$visited) |
|
2107 | { |
|
2108 | $class = $this->dm->getClassMetadata(get_class($document)); |
|
2109 | foreach ($class->fieldMappings as $mapping) { |
|
2110 | if ( ! $mapping['isCascadeDetach']) { |
|
2111 | continue; |
|
2112 | } |
|
2113 | $relatedDocuments = $class->reflFields[$mapping['fieldName']]->getValue($document); |
|
2114 | if (($relatedDocuments instanceof Collection || is_array($relatedDocuments))) { |
|
2115 | if ($relatedDocuments instanceof PersistentCollectionInterface) { |
|
2116 | // Unwrap so that foreach() does not initialize |
|
2117 | $relatedDocuments = $relatedDocuments->unwrap(); |
|
2118 | } |
|
2119 | foreach ($relatedDocuments as $relatedDocument) { |
|
2120 | $this->doDetach($relatedDocument, $visited); |
|
2121 | } |
|
2122 | } elseif ($relatedDocuments !== null) { |
|
2123 | $this->doDetach($relatedDocuments, $visited); |
|
2124 | } |
|
2125 | } |
|
2126 | } |
|
2127 | /** |
|
2128 | * Cascades a merge operation to associated documents. |
|
2129 | * |
|
@@ 2221-2242 (lines=22) @@ | ||
2218 | * @param object $document |
|
2219 | * @param array $visited |
|
2220 | */ |
|
2221 | private function cascadeRemove($document, array &$visited) |
|
2222 | { |
|
2223 | $class = $this->dm->getClassMetadata(get_class($document)); |
|
2224 | foreach ($class->fieldMappings as $mapping) { |
|
2225 | if ( ! $mapping['isCascadeRemove']) { |
|
2226 | continue; |
|
2227 | } |
|
2228 | if ($document instanceof Proxy && ! $document->__isInitialized__) { |
|
2229 | $document->__load(); |
|
2230 | } |
|
2231 | ||
2232 | $relatedDocuments = $class->reflFields[$mapping['fieldName']]->getValue($document); |
|
2233 | if ($relatedDocuments instanceof Collection || is_array($relatedDocuments)) { |
|
2234 | // If its a PersistentCollection initialization is intended! No unwrap! |
|
2235 | foreach ($relatedDocuments as $relatedDocument) { |
|
2236 | $this->doRemove($relatedDocument, $visited); |
|
2237 | } |
|
2238 | } elseif ($relatedDocuments !== null) { |
|
2239 | $this->doRemove($relatedDocuments, $visited); |
|
2240 | } |
|
2241 | } |
|
2242 | } |
|
2243 | ||
2244 | /** |
|
2245 | * Acquire a lock on the given document. |