From c65695b807cb3e951da3d4287343917b8b2e510c Mon Sep 17 00:00:00 2001 From: Andrew O'Neil Date: Tue, 12 Jan 2010 01:40:36 +0000 Subject: [PATCH] BUGFIX: Allow set objects as properties if the property is not a database field git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@96663 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/model/DataObject.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/core/model/DataObject.php b/core/model/DataObject.php index 122e9a1bd..0f798181e 100755 --- a/core/model/DataObject.php +++ b/core/model/DataObject.php @@ -2041,16 +2041,17 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity * @param mixed $val New field value */ function setField($fieldName, $val) { - // Situation 1: Passing an object - if(is_object($val)) { - if($val instanceof DBField) { - $val->Name = $fieldName; - $this->record[$fieldName] = $val; - } else { + // Situation 1: Passing an DBField + if($val instanceof DBField) { + $val->Name = $fieldName; + $this->record[$fieldName] = $val; + // Situation 2: Passing a literal or non-DBField object + } else { + // If this is a proper database field, we shouldn't be getting non-DBField objects + if(is_object($val) && $this->db($fieldName)) { user_error('DataObject::setField: passed an object that is not a DBField', E_USER_WARNING); } - // Situation 2: Passing a literal - } else { + $defaults = $this->stat('defaults'); // if a field is not existing or has strictly changed if(!isset($this->record[$fieldName]) || $this->record[$fieldName] !== $val) {