mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
DataDifferencer ignoreFields chainable, adjusted dbObject to check that the field is a db field
This commit is contained in:
parent
e0a51bfb02
commit
333f27badd
@ -2954,24 +2954,27 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
* @return DBField The field as a DBField object
|
* @return DBField The field as a DBField object
|
||||||
*/
|
*/
|
||||||
public function dbObject($fieldName) {
|
public function dbObject($fieldName) {
|
||||||
|
// Check for field in DB
|
||||||
|
$helper = $this->db($fieldName, true);
|
||||||
|
|
||||||
|
if(!$helper) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
$value = isset($this->record[$fieldName])
|
$value = isset($this->record[$fieldName])
|
||||||
? $this->record[$fieldName]
|
? $this->record[$fieldName]
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
// If we have a DBField object in $this->record, then return that
|
// If we have a DBField object in $this->record, then return that
|
||||||
if(is_object($value)) {
|
if($value instanceof DBField) {
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build and populate new field otherwise
|
list($table, $spec) = explode('.', $helper);
|
||||||
$helper = $this->db($fieldName, true);
|
$obj = Object::create_from_string($spec, $fieldName);
|
||||||
if($helper) {
|
$obj->setTable($table);
|
||||||
list($table, $spec) = explode('.', $helper);
|
$obj->setValue($value, $this, false);
|
||||||
$obj = Object::create_from_string($spec, $fieldName);
|
return $obj;
|
||||||
$obj->setTable($table);
|
|
||||||
$obj->setValue($value, $this, false);
|
|
||||||
return $obj;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -75,6 +75,8 @@ class DataDifferencer extends ViewableData {
|
|||||||
public function ignoreFields($ignoredFields) {
|
public function ignoreFields($ignoredFields) {
|
||||||
if(!is_array($ignoredFields)) $ignoredFields = func_get_args();
|
if(!is_array($ignoredFields)) $ignoredFields = func_get_args();
|
||||||
$this->ignoredFields = array_merge($this->ignoredFields, $ignoredFields);
|
$this->ignoredFields = array_merge($this->ignoredFields, $ignoredFields);
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user