mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX Fixing DataObject->hasField() to find fields in inherited database tables by using hasDatabaseField().
BUGFIX Fixing DataObject->hasField() to detect dynamic getters by using hasMethod("get$fieldName") ENHANCEMENT Re-enabled two test cases in DataObjectSet as a result of the above fixes git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@63999 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
67f144e1a5
commit
b1b909103e
@ -1217,10 +1217,10 @@ class DataObject extends ViewableData implements DataObjectInterface {
|
||||
$relationshipFields = singleton($component)->summaryFields();
|
||||
$foreignKey = $this->getComponentJoinField($relationship);
|
||||
$ctf = new ComplexTableField(
|
||||
$this,
|
||||
$relationship,
|
||||
$component,
|
||||
$relationshipFields,
|
||||
$this,
|
||||
$relationship,
|
||||
$component,
|
||||
$relationshipFields,
|
||||
"getCMSFields",
|
||||
"$foreignKey = $this->ID"
|
||||
);
|
||||
@ -1775,13 +1775,14 @@ class DataObject extends ViewableData implements DataObjectInterface {
|
||||
|
||||
/**
|
||||
* Returns true if the given field exists
|
||||
* in a database column on any of the objects tables,
|
||||
* or as a dynamic getter with get<fieldName>().
|
||||
*
|
||||
* @param string $field Name of the field
|
||||
*
|
||||
* @return boolean True if the given field exists
|
||||
*/
|
||||
public function hasField($field) {
|
||||
return array_key_exists($field, $this->record) || $this->hasOwnTableDatabaseField($field);
|
||||
return array_key_exists($field, $this->record) || $this->hasDatabaseField($field) || $this->hasMethod("get{$field}");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -348,7 +348,7 @@ class DataObjectTest extends SapphireTest {
|
||||
$this->assertTrue($teamInstance->hasField('Created'), 'hasField() finds built-in fields in instances');
|
||||
$this->assertTrue($teamInstance->hasField('DatabaseField'), 'hasField() finds custom fields in instances');
|
||||
//$this->assertFalse($teamInstance->hasField('SubclassDatabaseField'), 'hasField() doesnt find subclass fields in parentclass instances');
|
||||
//$this->assertTrue($teamInstance->hasField('DynamicField'), 'hasField() finds dynamic getters in instances');
|
||||
$this->assertTrue($teamInstance->hasField('DynamicField'), 'hasField() finds dynamic getters in instances');
|
||||
$this->assertTrue($teamInstance->hasField('HasOneRelationshipID'), 'hasField() finds foreign keys in instances');
|
||||
$this->assertTrue($teamInstance->hasField('DecoratedDatabaseField'), 'hasField() finds decorated fields in instances');
|
||||
$this->assertTrue($teamInstance->hasField('DecoratedHasOneRelationshipID'), 'hasField() finds decorated foreign keys in instances');
|
||||
@ -359,7 +359,7 @@ class DataObjectTest extends SapphireTest {
|
||||
$this->assertTrue($subteamInstance->hasField('Created'), 'hasField() finds built-in fields in subclass instances');
|
||||
$this->assertTrue($subteamInstance->hasField('DatabaseField'), 'hasField() finds custom fields in subclass instances');
|
||||
$this->assertTrue($subteamInstance->hasField('SubclassDatabaseField'), 'hasField() finds custom fields in subclass instances');
|
||||
//$this->assertTrue($subteamInstance->hasField('DynamicField'), 'hasField() finds dynamic getters in subclass instances');
|
||||
$this->assertTrue($subteamInstance->hasField('DynamicField'), 'hasField() finds dynamic getters in subclass instances');
|
||||
$this->assertTrue($subteamInstance->hasField('HasOneRelationshipID'), 'hasField() finds foreign keys in subclass instances');
|
||||
$this->assertTrue($subteamInstance->hasField('DecoratedDatabaseField'), 'hasField() finds decorated fields in subclass instances');
|
||||
$this->assertTrue($subteamInstance->hasField('DecoratedHasOneRelationshipID'), 'hasField() finds decorated foreign keys in subclass instances');
|
||||
|
Loading…
Reference in New Issue
Block a user