Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem modifying existing entity with enum and saving it #61

Open
kaihoefler opened this issue May 4, 2024 · 0 comments
Open

Problem modifying existing entity with enum and saving it #61

kaihoefler opened this issue May 4, 2024 · 0 comments

Comments

@kaihoefler
Copy link
Contributor

kaihoefler commented May 4, 2024

Hi,
I'm sorry but I have another problem after migration my application which uses Enum form Cake 3 to Cake 5:

I have an Entity e.g. Article which contains an enum attribute visibility.
The enum is defined as follows:

$this->addBehavior('CakeDC/Enum.Enum', ['lists' => [ 'visibility' => [ 'strategy' => 'const', 'prefix' => 'VISIBILITY', 'field' => 'visibility', 'translate' => true ] ]]);

When I read an existing entity and modify it in the controller,

$article = $this->Articles->get($id); $article->count_viewed = $article->count_viewed + 1; $this->Articles->save($article));

the save operation is throwing a TypeError

"array_key_exists(): Argument #1 ($key) must be a valid array offset type"
in ROOT/vendor/cakedc/enum/src/Model/Behavior/EnumBehavior.php at line 299

As far as I see the problem originates by the fact that after reading the visibility attribute is an object(Cake\ORM\Entity) but when I save the value a string is expected.
Because after

$article->visibility = $article->visibility->value;

saving ist possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant