BUG Update Company validate method to reflect best practices.

This commit is contained in:
Maxime Rainville 2020-09-17 15:13:47 +12:00
parent 11c4dd857b
commit 4d2d3628e0

View File

@ -47,7 +47,7 @@ class Company extends DataObject
'Name'=>'Varchar(255)', 'Name'=>'Varchar(255)',
'Category'=>'Varchar(255)', 'Category'=>'Varchar(255)',
'Revenue'=>'Float', 'Revenue'=>'Float',
'CEO'=>'Varchar(255)', 'CEO'=>'Varchar(255)'
); );
private static $has_one = array( private static $has_one = array(
@ -102,13 +102,13 @@ class Company extends DataObject
public function validate() public function validate()
{ {
if (!$this->Title) { $result = parent::validate();
$result = new ValidationResult();
$result->addError('Title is required'); if (!$this->Name) {
return $result; $result->addFieldError('Name', 'Name is required');
} else {
return parent::validate();
} }
return $result;
} }
public function DynamicProperty() public function DynamicProperty()