Skip to content
Permalink
Browse files

add convenient checks for not-nullable nulls for "allowPartialNulls" …

…flag
  • Loading branch information...
Jonas
Jonas committed Jun 17, 2016
1 parent 15bbb99 commit acbacd175284654dda0f44aa458147cf957443aa
Showing with 11 additions and 5 deletions.
  1. +11 −5 src/ORM/Rule/ExistsIn.php
@@ -129,7 +129,7 @@ public function __invoke(EntityInterface $entity, array $options)
}
/**
* Check whether or not the entity fields are nullable and null.
* Checks whether or not the given entity fields are nullable and null.
*
* @param \Cake\Datasource\EntityInterface $entity The entity to check.
* @param \Cake\ORM\Table $source The table to use schema from.
@@ -148,7 +148,8 @@ protected function _fieldsAreNull($entity, $source)
}
/**
* Check whether there are nullable nulls in at least one part of the foreign key.
* Checks whether or not the give entity fields are null and map to schema NULL
* or are not null and map to schema NOT NULL.
*
* @param \Cake\Datasource\EntityInterface $entity The entity to check.
* @param \Cake\ORM\Table $source The table to use schema from.
@@ -158,10 +159,15 @@ protected function _checkPartialSchemaNulls($entity, $source)
{
$schema = $source->schema();
foreach ($this->_fields as $field) {
if ($schema->isNullable($field) && $entity->get($field) === null) {
return true;
$isNullable = $schema->isNullable($field);
$value = $entity->get($field);
if (!$isNullable && $value === null) {
return false;
}
if ($isNullable && $value !== null) {
return false;
}
}
return false;
return true;
}
}

0 comments on commit acbacd1

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