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