Skip to content

Commit 49b74e2

Browse files
committed
fixed enum validation, fixed property conflict in lookup strategy, fixed migration
1 parent 90dc3a7 commit 49b74e2

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

src/Model/Behavior/EnumBehavior.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use ArrayObject;
1717
use BadMethodCallException;
18+
use Cake\Datasource\EntityInterface;
1819
use Cake\Event\EventInterface;
1920
use Cake\ORM\Behavior;
2021
use Cake\ORM\Query\SelectQuery;
@@ -295,8 +296,14 @@ public function __call(string $method, array $args): bool
295296
if ($entity->isEmpty($config['field']) && Hash::get($config, 'allowEmpty') === true) {
296297
return true;
297298
}
299+
$value = $entity->{$config['field']};
300+
if (is_array($value)) {
301+
$value = $value['value'] ?? '';
302+
} elseif ($value instanceof EntityInterface) {
303+
$value = $value->get('value');
304+
}
298305

299-
return array_key_exists($entity->{$config['field']}, $this->enum($alias));
306+
return array_key_exists($value, $this->enum($alias));
300307
}
301308

302309
/**

src/Model/Behavior/Strategy/LookupStrategy.php

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public function initialize(array $config): void
5959

6060
$this->table
6161
->belongsTo($assocName)
62+
->setProperty($assocName."Enum")
6263
->setClassName('CakeDC/Enum.Lookups')
6364
->setForeignKey($config['field'])
6465
->setBindingKey('name')

0 commit comments

Comments
 (0)