Skip to content

Commit

Permalink
Fixed validate() - fail if one of models failed to validate
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverFire committed Jun 10, 2015
1 parent a9eb1cd commit fd386c9
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,12 +366,32 @@ public function hasErrors () {
return false;
}

/**
* Returns the first error of the collection
*
* @return bool|mixed
*/
public function getFirstError () {
foreach ($this->models as $model) {
/* @var $model ActiveRecord */
if ($model->hasErrors()) {
$errors = $model->getFirstErrors();
return array_shift($errors);
}
}

return false;
}


public function validate ($attributes = null) {
if (!$this->beforeValidate()) {
return false;
}

$this->first->validateMultiple($this->models, $attributes);
if (!$this->first->validateMultiple($this->models, $attributes)) {
return false;
}

$this->afterValidate();

Expand Down

0 comments on commit fd386c9

Please sign in to comment.