From 4d2d3628e03b2ddfd2c7da7133f797c672d6c23c Mon Sep 17 00:00:00 2001 From: Maxime Rainville Date: Thu, 17 Sep 2020 15:13:47 +1200 Subject: [PATCH] BUG Update Company validate method to reflect best practices. --- code/Company.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/code/Company.php b/code/Company.php index 4a1e662..d03d2ba 100644 --- a/code/Company.php +++ b/code/Company.php @@ -47,7 +47,7 @@ class Company extends DataObject 'Name'=>'Varchar(255)', 'Category'=>'Varchar(255)', 'Revenue'=>'Float', - 'CEO'=>'Varchar(255)', + 'CEO'=>'Varchar(255)' ); private static $has_one = array( @@ -102,13 +102,13 @@ class Company extends DataObject public function validate() { - if (!$this->Title) { - $result = new ValidationResult(); - $result->addError('Title is required'); - return $result; - } else { - return parent::validate(); + $result = parent::validate(); + + if (!$this->Name) { + $result->addFieldError('Name', 'Name is required'); } + + return $result; } public function DynamicProperty()