|
|
@@ -130,11 +130,10 @@ class ModelValidator implements ArrayAccess, IteratorAggregate, Countable {
|
|
|
$options = array_merge(array('atomic' => true, 'deep' => false), $options);
|
|
|
$model->validationErrors = $validationErrors = $return = array();
|
|
|
$model->create(null);
|
|
|
+ $return[$model->alias] = true;
|
|
|
if (!($model->set($data) && $model->validates($options))) {
|
|
|
$validationErrors[$model->alias] = $model->validationErrors;
|
|
|
$return[$model->alias] = false;
|
|
|
- } else {
|
|
|
- $return[$model->alias] = true;
|
|
|
}
|
|
|
$data = $model->data;
|
|
|
if (!empty($options['deep']) && isset($data[$model->alias])) {
|
|
|
@@ -156,10 +155,9 @@ class ModelValidator implements ArrayAccess, IteratorAggregate, Countable {
|
|
|
$data[$association] = $model->{$association}->data[$model->{$association}->alias];
|
|
|
}
|
|
|
if (is_array($validates)) {
|
|
|
+ $validates = true;
|
|
|
if (in_array(false, Hash::flatten($validates), true)) {
|
|
|
$validates = false;
|
|
|
- } else {
|
|
|
- $validates = true;
|
|
|
}
|
|
|
}
|
|
|
$return[$association] = $validates;
|
|
|
@@ -219,11 +217,10 @@ class ModelValidator implements ArrayAccess, IteratorAggregate, Countable {
|
|
|
$validates = $model->set($record) && $model->validates($options);
|
|
|
$data[$key] = $model->data;
|
|
|
}
|
|
|
+ $validates = true;
|
|
|
if ($validates === false || (is_array($validates) && in_array(false, Hash::flatten($validates), true))) {
|
|
|
$validationErrors[$key] = $model->validationErrors;
|
|
|
$validates = false;
|
|
|
- } else {
|
|
|
- $validates = true;
|
|
|
}
|
|
|
$return[$key] = $validates;
|
|
|
}
|
|
|
@@ -231,10 +228,7 @@ class ModelValidator implements ArrayAccess, IteratorAggregate, Countable {
|
|
|
if (!$options['atomic']) {
|
|
|
return $return;
|
|
|
}
|
|
|
- if (empty($model->validationErrors)) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- return false;
|
|
|
+ return empty($model->validationErrors);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -322,9 +316,10 @@ class ModelValidator implements ArrayAccess, IteratorAggregate, Countable {
|
|
|
*/
|
|
|
public function getField($name = null) {
|
|
|
$this->_parseRules();
|
|
|
- if ($name !== null && !empty($this->_fields[$name])) {
|
|
|
- return $this->_fields[$name];
|
|
|
- } elseif ($name !== null) {
|
|
|
+ if ($name !== null) {
|
|
|
+ if (!empty($this->_fields[$name])) {
|
|
|
+ return $this->_fields[$name];
|
|
|
+ }
|
|
|
return null;
|
|
|
}
|
|
|
return $this->_fields;
|
|
|
@@ -401,16 +396,15 @@ class ModelValidator implements ArrayAccess, IteratorAggregate, Countable {
|
|
|
unset($fieldList);
|
|
|
|
|
|
$validateList = array();
|
|
|
- if (!empty($whitelist)) {
|
|
|
- $this->validationErrors = array();
|
|
|
+ if (empty($whitelist)) {
|
|
|
+ return $this->_fields;
|
|
|
+ }
|
|
|
|
|
|
- foreach ((array)$whitelist as $f) {
|
|
|
- if (!empty($this->_fields[$f])) {
|
|
|
- $validateList[$f] = $this->_fields[$f];
|
|
|
- }
|
|
|
+ $this->validationErrors = array();
|
|
|
+ foreach ((array)$whitelist as $f) {
|
|
|
+ if (!empty($this->_fields[$f])) {
|
|
|
+ $validateList[$f] = $this->_fields[$f];
|
|
|
}
|
|
|
- } else {
|
|
|
- return $this->_fields;
|
|
|
}
|
|
|
|
|
|
return $validateList;
|
|
|
@@ -443,9 +437,6 @@ class ModelValidator implements ArrayAccess, IteratorAggregate, Countable {
|
|
|
$newData[] = $row[$join];
|
|
|
}
|
|
|
}
|
|
|
- if (empty($newData)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
foreach ($newData as $data) {
|
|
|
$data[$model->hasAndBelongsToMany[$assoc]['foreignKey']] = $model->id;
|
|
|
$model->{$join}->create($data);
|