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

CRUD with updated value outside model condition #2204

Open
nocelab opened this issue Apr 18, 2024 · 2 comments
Open

CRUD with updated value outside model condition #2204

nocelab opened this issue Apr 18, 2024 · 2 comments
Labels

Comments

@nocelab
Copy link

nocelab commented Apr 18, 2024

I need to set a Crud with a records subset.
The Model has the combo field:

$this->addField('tipo', ['values' => ['x' => 'fix', '+' => 'new', '-' => 'removed']]);

and I add condition with:

$mod->addCondition($mod->expr("tipo = '+'"));

Crud show correctly the recordset but when I try to edit a row, changing tipo value, I get this error on saving:

Critical Error
Atk4\Data\Exception: Record with specified ID was not found

model: Modello
id: 3311
scope: 'expression 'tipo = '+'''
action: Atk4\Data\Model\UserAction (edit)
@nocelab nocelab changed the title Crud with AddCondition() CRUD with AddCondition() Apr 18, 2024
@mkrecek234
Copy link
Contributor

This is the situation by design as by changing that value the entity would drop out of the model.

See discussion here atk4/data#1052

You need to make sure that onSubmit the model is unconditioned that is used to save the changed entity, and the conditioned model is only used to display the crud.

Agree that this it not very intuitive and good tips welcome what the best way to code it might look like

@nocelab
Copy link
Author

nocelab commented Apr 18, 2024

Thanks... very happy that someone has a similar situation!!!
I need to deep read the post to understand better if there is my answer... but it's sure the right way.

I also tried to modified demos/crud.php adding:

$model->addCondition($model->fieldName()->name, 'like', "I%");

saving one edited row (changing the Name with something not starting with "I") works good without error... but looking source code I don't realize why

@mvorisek mvorisek changed the title CRUD with AddCondition() CRUD with updated value outside model condition Jun 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants