BUGFIX: Allow set objects as properties if the property is not a database field (from r96663)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@102329 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2010-04-12 01:36:30 +00:00
parent 58782bcf2a
commit 22e789e916

View File

@ -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) {