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