From 55cb8f37ead284895b42a3fdc863f37071cfdefb Mon Sep 17 00:00:00 2001 From: Jackson Darlow Date: Tue, 16 Jun 2020 17:08:19 +1200 Subject: [PATCH 1/2] Added a check for configured fieldname conflict with inherited methods --- src/ORM/DataObject.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/ORM/DataObject.php b/src/ORM/DataObject.php index b34cb9a86..112070d54 100644 --- a/src/ORM/DataObject.php +++ b/src/ORM/DataObject.php @@ -3451,6 +3451,17 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity ); } + // Sanity check for fields that conflict with parent + foreach (array_keys($fields) as $fieldName) { + if (method_exists(get_parent_class($this), $fieldName)) { + throw new LogicException(sprintf( + '\'%s\' has a $db field named "%s" that coincides with an inherited method of the same name.', + static::class, + $fieldName + )); + } + } + if ($fields) { $hasAutoIncPK = get_parent_class($this) === self::class; DB::require_table( From 2a59b1b3879cbfbd068313a3901f98c7f794a9bc Mon Sep 17 00:00:00 2001 From: Jackson Darlow Date: Wed, 17 Jun 2020 11:22:44 +1200 Subject: [PATCH 2/2] Excluded TestOnly classes from field conflict check --- src/ORM/DataObject.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ORM/DataObject.php b/src/ORM/DataObject.php index 112070d54..9d40d7b5b 100644 --- a/src/ORM/DataObject.php +++ b/src/ORM/DataObject.php @@ -12,6 +12,7 @@ use SilverStripe\Core\Injector\Injector; use SilverStripe\Core\Resettable; use SilverStripe\Dev\Debug; use SilverStripe\Dev\Deprecation; +use SilverStripe\Dev\TestOnly; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\FormField; use SilverStripe\Forms\FormScaffolder; @@ -3453,7 +3454,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity // Sanity check for fields that conflict with parent foreach (array_keys($fields) as $fieldName) { - if (method_exists(get_parent_class($this), $fieldName)) { + if (method_exists(get_parent_class($this), $fieldName) && !($this instanceof TestOnly)) { throw new LogicException(sprintf( '\'%s\' has a $db field named "%s" that coincides with an inherited method of the same name.', static::class,