Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #868 from halkyon/dataobject_model

BUG Fixing model not being set before populateDefaults()
  • Loading branch information...
commit a4afea127ea5abada049799ae45aeb8d95cad8a1 2 parents fa29930 + bc34580
@sminnee sminnee authored
Showing with 5 additions and 4 deletions.
  1. +5 −4 model/DataObject.php
View
9 model/DataObject.php
@@ -312,7 +312,6 @@ private static function cache_composite_fields($class) {
* Singletons don't have their defaults set.
*/
public function __construct($record = null, $isSingleton = false, $model = null) {
-
parent::__construct();
// Set the fields data.
@@ -366,6 +365,10 @@ public function __construct($record = null, $isSingleton = false, $model = null)
HTTP::register_modification_date($record['LastEdited']);
}
+ // this must be called before populateDefaults(), as field getters on a DataObject
+ // may call getComponent() and others, which rely on $this->model being set.
+ $this->model = $model ? $model : DataModel::inst();
+
// Must be called after parent constructor
if(!$isSingleton && (!isset($this->record['ID']) || !$this->record['ID'])) {
$this->populateDefaults();
@@ -373,8 +376,6 @@ public function __construct($record = null, $isSingleton = false, $model = null)
// prevent populateDefaults() and setField() from marking overwritten defaults as changed
$this->changed = array();
-
- $this->model = $model ? $model : DataModel::inst();
}
/**
@@ -1303,7 +1304,7 @@ public function getComponent($componentName) {
if($joinID) {
$component = $this->model->$class->byID($joinID);
}
-
+
if(!isset($component) || !$component) {
$component = $this->model->$class->newObject();
}
Please sign in to comment.
Something went wrong with that request. Please try again.