Skip to content

Commit

Permalink
fixed enum validation, fixed property conflict in lookup strategy, fi…
Browse files Browse the repository at this point in the history
…xed migration
  • Loading branch information
arusinowski committed Jan 6, 2025
1 parent 90dc3a7 commit 49b74e2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Model/Behavior/EnumBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use ArrayObject;
use BadMethodCallException;
use Cake\Datasource\EntityInterface;
use Cake\Event\EventInterface;
use Cake\ORM\Behavior;
use Cake\ORM\Query\SelectQuery;
Expand Down Expand Up @@ -295,8 +296,14 @@ public function __call(string $method, array $args): bool
if ($entity->isEmpty($config['field']) && Hash::get($config, 'allowEmpty') === true) {
return true;
}
$value = $entity->{$config['field']};
if (is_array($value)) {
$value = $value['value'] ?? '';
} elseif ($value instanceof EntityInterface) {
$value = $value->get('value');
}

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

/**
Expand Down
1 change: 1 addition & 0 deletions src/Model/Behavior/Strategy/LookupStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public function initialize(array $config): void

$this->table
->belongsTo($assocName)
->setProperty($assocName."Enum")

Check failure on line 62 in src/Model/Behavior/Strategy/LookupStrategy.php

View workflow job for this annotation

GitHub Actions / cs-stan / Coding Standard & Static Analysis

Expected at least 1 space before "."; 0 found

Check failure on line 62 in src/Model/Behavior/Strategy/LookupStrategy.php

View workflow job for this annotation

GitHub Actions / cs-stan / Coding Standard & Static Analysis

Expected at least 1 space after "."; 0 found

Check failure on line 62 in src/Model/Behavior/Strategy/LookupStrategy.php

View workflow job for this annotation

GitHub Actions / cs-stan / Coding Standard & Static Analysis

Use single instead of double quotes for simple strings.
->setClassName('CakeDC/Enum.Lookups')
->setForeignKey($config['field'])
->setBindingKey('name')
Expand Down

0 comments on commit 49b74e2

Please sign in to comment.