Skip to content
Permalink
Browse files

Fixed issues found in review

  • Loading branch information...
lorenzo committed Dec 24, 2013
1 parent b698320 commit 4bca3207adcdceb2d52057ac7902f329b58216f0
Showing with 27 additions and 25 deletions.
  1. +10 −9 Cake/ORM/Entity.php
  2. +3 −4 Cake/ORM/EntityValidator.php
  3. +8 −6 Cake/ORM/Table.php
  4. +6 −6 Cake/Test/TestCase/ORM/EntityTest.php
@@ -635,14 +635,6 @@ protected function _nestedErrors($field) {
}
$value = $this->_properties[$field];
if (is_scalar($value) || (is_object($value) && !($value instanceof self))) {
return [];
}
if ($value instanceof self) {
return $value->errors();
}
$errors = [];
if (is_array($value) || $value instanceof \Traversable) {
foreach ($value as $k => $v) {
@@ -651,9 +643,18 @@ protected function _nestedErrors($field) {
}
$errors[$k] = $v->errors();
}
return $errors;
}
if (is_scalar($value) || !($value instanceof self)) {
return [];
}
if ($value instanceof self) {
return $value->errors();
}
return $errors;
return [];
}
/**
@@ -17,7 +17,7 @@
use Cake\Event\Event;
/**
* Contains logic for validate entities and their associations
* Contains logic for validating entities and their associations
*
* @see Cake\ORM\Table::validate()
* @see Cake\ORM\Table::validateMany()
@@ -54,7 +54,7 @@ protected function _buildPropertyMap($include) {
foreach ($include['associated'] as $key => $options) {
if (is_int($key) && is_scalar($options)) {
$key = $options;
$options = ['validate' => true, 'associated' => []];
$options = [];
}
$options += ['validate' => true, 'associated' => []];
@@ -104,8 +104,7 @@ public function one(Entity $entity, $options = []) {
$options['validate'] = true;
}
$valid = $this->_processValidation($entity, $options) && $valid;
return $valid;
return $this->_processValidation($entity, $options) && $valid;
}
/**
@@ -1572,21 +1572,21 @@ public function newEntities(array $data, $associations = null) {
* they are saved.
*
* {{{
* $articles = $this->Articles->validate($article);
* $articles->validate($article);
* }}}
*
* You can specify which validation set to use using the options array:
*
* {{{
* $articles = $this->Users->validate($user, ['validate' => 'forSignup']);
* $users->validate($user, ['validate' => 'forSignup']);
* }}}
*
* By default all the associations on this table will be validated if they can
* be found in the passed entity. You can limit which associations are built,
* or include deeper associations using the options parameter
*
* {{{
* $articles = $this->Articles->validate($article, [
* $articles->validate($article, [
* 'associated' => [
* 'Tags',
* 'Comments' => [
@@ -1602,6 +1602,7 @@ public function newEntities(array $data, $associations = null) {
* keys are accepted:
* - validate: The name of the validation set to use
* - associated: map of association names to validate as well
* @return boolean true if the passed entity and its associations are valid
*/
public function validate($entity, $options = []) {
if (!isset($options['associated'])) {
@@ -1622,21 +1623,21 @@ public function validate($entity, $options = []) {
* saved.
*
* {{{
* $articles = $this->Articles->validate([$article1, $article2]);
* $articles->validate([$article1, $article2]);
* }}}
*
* You can specify which validation set to use using the options array:
*
* {{{
* $articles = $this->Users->validate([$user1, $user2], ['validate' => 'forSignup']);
* $users->validate([$user1, $user2], ['validate' => 'forSignup']);
* }}}
*
* By default all the associations on this table will be validated if they can
* be found in the passed entities. You can limit which associations are built,
* or include deeper associations using the options parameter
*
* {{{
* $articles = $this->Articles->validate([$article1, $article2], [
* $articles->validate([$article1, $article2], [
* 'associated' => [
* 'Tags',
* 'Comments' => [
@@ -1652,6 +1653,7 @@ public function validate($entity, $options = []) {
* keys are accepted:
* - validate: The name of the validation set to use
* - associated: map of association names to validate as well
* @return boolean true if the passed entities and their associations are valid
*/
public function validateMany($entities, $options = []) {
if (!isset($options['associated'])) {
@@ -787,14 +787,14 @@ public function testErrors() {
* @return void
*/
public function testErrorsDeep() {
$entity = new Entity;
$entity2 = new Entity;
$entity3 = new Entity;
$entity->set('foo', 'bar');
$entity->set('thing', 'baz');
$entity->set('user', $entity2);
$entity->set('owner', $entity3);
$entity = new Entity([
'foo' => 'bar',
'thing' => 'baz',
'user' => $entity2,
'owner' => $entity3
]);
$entity->errors('thing', ['this is a mistake']);
$entity2->errors(['a' => ['error1'], 'b' => ['error2']]);
$entity3->errors(['c' => ['error3'], 'd' => ['error4']]);

0 comments on commit 4bca320

Please sign in to comment.
You can’t perform that action at this time.