Skip to content
This repository
Browse code

BUG $db in extensions not inited early enough (#7598)

When querying DataObjects by a generic parent class (like SiteTree for instance), fields added via $db
set on child classes wouldnt appear.

This is because Object::__construct wasnt called early enough in DataObject::__construct, so
extensions werent initialised when $db was first accessed
  • Loading branch information...
commit 890f7e3919c819cf0ef9dbd61649b43dcae43faa 1 parent ea910a5
Hamish Friedlander authored

Showing 1 changed file with 3 additions and 2 deletions. Show diff stats Hide diff stats

  1. 5  model/DataObject.php
5  model/DataObject.php
@@ -295,6 +295,9 @@ private static function cache_composite_fields($class) {
295 295
 	 * don't have their defaults set.
296 296
 	 */
297 297
 	function __construct($record = null, $isSingleton = false, $model = null) {
  298
+
  299
+		parent::__construct();
  300
+
298 301
 		// Set the fields data.
299 302
 		if(!$record) {
300 303
 			$record = array(
@@ -345,8 +348,6 @@ function __construct($record = null, $isSingleton = false, $model = null) {
345 348
 			HTTP::register_modification_date($record['LastEdited']);
346 349
 		}
347 350
 
348  
-		parent::__construct();
349  
-
350 351
 		// Must be called after parent constructor
351 352
 		if(!$isSingleton && (!isset($this->record['ID']) || !$this->record['ID'])) {
352 353
 			$this->populateDefaults();

0 notes on commit 890f7e3

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