mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-11 19:25:18 +02:00
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
This commit is contained in:
parent
d5a04edf02
commit
c65695b807
@ -2041,16 +2041,17 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
* @param mixed $val New field value
|
* @param mixed $val New field value
|
||||||
*/
|
*/
|
||||||
function setField($fieldName, $val) {
|
function setField($fieldName, $val) {
|
||||||
// Situation 1: Passing an object
|
// Situation 1: Passing an DBField
|
||||||
if(is_object($val)) {
|
|
||||||
if($val instanceof DBField) {
|
if($val instanceof DBField) {
|
||||||
$val->Name = $fieldName;
|
$val->Name = $fieldName;
|
||||||
$this->record[$fieldName] = $val;
|
$this->record[$fieldName] = $val;
|
||||||
|
// Situation 2: Passing a literal or non-DBField object
|
||||||
} else {
|
} 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);
|
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');
|
$defaults = $this->stat('defaults');
|
||||||
// if a field is not existing or has strictly changed
|
// if a field is not existing or has strictly changed
|
||||||
if(!isset($this->record[$fieldName]) || $this->record[$fieldName] !== $val) {
|
if(!isset($this->record[$fieldName]) || $this->record[$fieldName] !== $val) {
|
||||||
|
Loading…
Reference in New Issue
Block a user