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:
Ingo Schommer 2008-10-09 14:38:46 +00:00
parent 67f144e1a5
commit b1b909103e
2 changed files with 9 additions and 8 deletions

View File

@ -1217,10 +1217,10 @@ class DataObject extends ViewableData implements DataObjectInterface {
$relationshipFields = singleton($component)->summaryFields(); $relationshipFields = singleton($component)->summaryFields();
$foreignKey = $this->getComponentJoinField($relationship); $foreignKey = $this->getComponentJoinField($relationship);
$ctf = new ComplexTableField( $ctf = new ComplexTableField(
$this, $this,
$relationship, $relationship,
$component, $component,
$relationshipFields, $relationshipFields,
"getCMSFields", "getCMSFields",
"$foreignKey = $this->ID" "$foreignKey = $this->ID"
); );
@ -1775,13 +1775,14 @@ class DataObject extends ViewableData implements DataObjectInterface {
/** /**
* Returns true if the given field exists * 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 * @param string $field Name of the field
*
* @return boolean True if the given field exists * @return boolean True if the given field exists
*/ */
public function hasField($field) { 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}");
} }
/** /**

View File

@ -348,7 +348,7 @@ class DataObjectTest extends SapphireTest {
$this->assertTrue($teamInstance->hasField('Created'), 'hasField() finds built-in fields in instances'); $this->assertTrue($teamInstance->hasField('Created'), 'hasField() finds built-in fields in instances');
$this->assertTrue($teamInstance->hasField('DatabaseField'), 'hasField() finds custom 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->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('HasOneRelationshipID'), 'hasField() finds foreign keys in instances');
$this->assertTrue($teamInstance->hasField('DecoratedDatabaseField'), 'hasField() finds decorated fields 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'); $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('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('DatabaseField'), 'hasField() finds custom fields in subclass instances');
$this->assertTrue($subteamInstance->hasField('SubclassDatabaseField'), '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('HasOneRelationshipID'), 'hasField() finds foreign keys in subclass instances');
$this->assertTrue($subteamInstance->hasField('DecoratedDatabaseField'), 'hasField() finds decorated fields 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'); $this->assertTrue($subteamInstance->hasField('DecoratedHasOneRelationshipID'), 'hasField() finds decorated foreign keys in subclass instances');