DataDifferencer ignoreFields chainable, adjusted dbObject to check that the field is a db field

This commit is contained in:
Christopher Joe 2016-08-01 21:47:39 +12:00
parent e0a51bfb02
commit 333f27badd
2 changed files with 15 additions and 10 deletions

View File

@ -2954,25 +2954,28 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
* @return DBField The field as a DBField object
*/
public function dbObject($fieldName) {
// Check for field in DB
$helper = $this->db($fieldName, true);
if(!$helper) {
return null;
}
$value = isset($this->record[$fieldName])
? $this->record[$fieldName]
: null;
// If we have a DBField object in $this->record, then return that
if(is_object($value)) {
if($value instanceof DBField) {
return $value;
}
// Build and populate new field otherwise
$helper = $this->db($fieldName, true);
if($helper) {
list($table, $spec) = explode('.', $helper);
$obj = Object::create_from_string($spec, $fieldName);
$obj->setTable($table);
$obj->setValue($value, $this, false);
return $obj;
}
}
/**
* Traverses to a DBField referenced by relationships between data objects.

View File

@ -75,6 +75,8 @@ class DataDifferencer extends ViewableData {
public function ignoreFields($ignoredFields) {
if(!is_array($ignoredFields)) $ignoredFields = func_get_args();
$this->ignoredFields = array_merge($this->ignoredFields, $ignoredFields);
return $this;
}
/**