@@ 2029-2049 (lines=21) @@ | ||
2026 | * @param object $document |
|
2027 | * @param array $visited |
|
2028 | */ |
|
2029 | private function cascadeDetach($document, array &$visited) |
|
2030 | { |
|
2031 | $class = $this->dm->getClassMetadata(get_class($document)); |
|
2032 | foreach ($class->fieldMappings as $mapping) { |
|
2033 | if ( ! $mapping['isCascadeDetach']) { |
|
2034 | continue; |
|
2035 | } |
|
2036 | $relatedDocuments = $class->reflFields[$mapping['fieldName']]->getValue($document); |
|
2037 | if (($relatedDocuments instanceof Collection || is_array($relatedDocuments))) { |
|
2038 | if ($relatedDocuments instanceof PersistentCollectionInterface) { |
|
2039 | // Unwrap so that foreach() does not initialize |
|
2040 | $relatedDocuments = $relatedDocuments->unwrap(); |
|
2041 | } |
|
2042 | foreach ($relatedDocuments as $relatedDocument) { |
|
2043 | $this->doDetach($relatedDocument, $visited); |
|
2044 | } |
|
2045 | } elseif ($relatedDocuments !== null) { |
|
2046 | $this->doDetach($relatedDocuments, $visited); |
|
2047 | } |
|
2048 | } |
|
2049 | } |
|
2050 | /** |
|
2051 | * Cascades a merge operation to associated documents. |
|
2052 | * |
|
@@ 2144-2165 (lines=22) @@ | ||
2141 | * @param object $document |
|
2142 | * @param array $visited |
|
2143 | */ |
|
2144 | private function cascadeRemove($document, array &$visited) |
|
2145 | { |
|
2146 | $class = $this->dm->getClassMetadata(get_class($document)); |
|
2147 | foreach ($class->fieldMappings as $mapping) { |
|
2148 | if ( ! $mapping['isCascadeRemove']) { |
|
2149 | continue; |
|
2150 | } |
|
2151 | if ($document instanceof Proxy && ! $document->__isInitialized__) { |
|
2152 | $document->__load(); |
|
2153 | } |
|
2154 | ||
2155 | $relatedDocuments = $class->reflFields[$mapping['fieldName']]->getValue($document); |
|
2156 | if ($relatedDocuments instanceof Collection || is_array($relatedDocuments)) { |
|
2157 | // If its a PersistentCollection initialization is intended! No unwrap! |
|
2158 | foreach ($relatedDocuments as $relatedDocument) { |
|
2159 | $this->doRemove($relatedDocument, $visited); |
|
2160 | } |
|
2161 | } elseif ($relatedDocuments !== null) { |
|
2162 | $this->doRemove($relatedDocuments, $visited); |
|
2163 | } |
|
2164 | } |
|
2165 | } |
|
2166 | ||
2167 | /** |
|
2168 | * Acquire a lock on the given document. |