Skip to content
This repository
Browse code

BUG trac 7482, we werent unlazying composite fields right

In getField we check if the field we are getting is currently lazy (unloaded), and
load it if it is. This was only working for simple fields though - composite
fields like Money werent working
  • Loading branch information...
commit 69928631fe918d13d27fd802d414084129fd9f93 1 parent 1a91431
Hamish Friedlander authored July 18, 2012

Showing 1 changed file with 11 additions and 7 deletions. Show diff stats Hide diff stats

  1. 18  model/DataObject.php
18  model/DataObject.php
@@ -1920,7 +1920,15 @@ public function getField($field) {
1920 1920
 		if(self::is_composite_field($this->class, $field)) {
1921 1921
 			$helper = $this->castingHelper($field);
1922 1922
 			$fieldObj = Object::create_from_string($helper, $field);
1923  
-			
  1923
+
  1924
+			$compositeFields = $fieldObj->compositeDatabaseFields();
  1925
+			foreach ($compositeFields as $compositeName => $compositeType) {
  1926
+				if(isset($this->record[$field.$compositeName.'_Lazy'])) {
  1927
+					$tableClass = $this->record[$field.$compositeName.'_Lazy'];
  1928
+					$this->loadLazyFields($tableClass);
  1929
+				}
  1930
+			}
  1931
+
1924 1932
 			// write value only if either the field value exists,
1925 1933
 			// or a valid record has been loaded from the database
1926 1934
 			$value = (isset($this->record[$field])) ? $this->record[$field] : null;
@@ -2092,9 +2100,7 @@ function setField($fieldName, $val) {
2092 2100
 			// If we've just lazy-loaded the column, then we need to populate the $original array by
2093 2101
 			// called getField(). Too much overhead? Could this be done by a quicker method? Maybe only
2094 2102
 			// on a call to getChanged()?
2095  
-			if (isset($this->record[$fieldName.'_Lazy'])) {
2096  
-				$this->getField($fieldName);
2097  
-			}
  2103
+			$this->getField($fieldName);
2098 2104
 
2099 2105
 			$this->record[$fieldName] = $val;
2100 2106
 		// Situation 2: Passing a literal or non-DBField object
@@ -2120,9 +2126,7 @@ function setField($fieldName, $val) {
2120 2126
 				// If we've just lazy-loaded the column, then we need to populate the $original array by
2121 2127
 				// called getField(). Too much overhead? Could this be done by a quicker method? Maybe only
2122 2128
 				// on a call to getChanged()?
2123  
-				if (isset($this->record[$fieldName.'_Lazy'])) {
2124  
-					$this->getField($fieldName);
2125  
-				}
  2129
+				$this->getField($fieldName);
2126 2130
 
2127 2131
 				// Value is always saved back when strict check succeeds.
2128 2132
 				$this->record[$fieldName] = $val;

0 notes on commit 6992863

Please sign in to comment.
Something went wrong with that request. Please try again.