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

Fix prevent soft delete all without conditions set #2090

Merged
merged 5 commits into from
Aug 20, 2019
Merged

Fix prevent soft delete all without conditions set #2090

merged 5 commits into from
Aug 20, 2019

Conversation

diegoldev
Copy link
Contributor

@diegoldev diegoldev commented Jul 8, 2019

Description
There's a bug, or at least a confuse behaviour, when you use soft-delete and execute $model->delete() method with empty value as parameter (0, NULL, FALSE, or simple no parameter).
When soft-delete is false, CI throw a DatabaseException warning about delete() method cannot execute without where or like condition, but, when soft-delete is true no exception nor warning is thrown because CI internally call update() method.
I modified the code in order to throw DatabaseException when soft-delete is true and $id parameter is empty and either a where condition was set.

In order to maintain consistance between both behaviour (hard and soft delete) I needed to add a getter to QBWhere property so that I be able to eval in Model if there's a condition set.
Additionally, I think that is usefull to be able to access to the compiled 'where' condition from any Model child class in case you want to modify it o just check

Checklist:

  • Securely signed commits
  • Component(s) with PHPdocs
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@MGatner
Copy link
Member

MGatner commented Jul 9, 2019

Nice PR! I commented on the exception language, but the bigger question of "was this a bug or desired behavior" will have to wait on the admins. I'm in favor of this change.

@lonnieezell lonnieezell merged commit e243b9f into codeigniter4:develop Aug 20, 2019
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

Successfully merging this pull request may close these issues.

3 participants