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

Bug: useSoftDeletes with like function #2380

Closed
edica opened this issue Nov 1, 2019 · 6 comments
Closed

Bug: useSoftDeletes with like function #2380

edica opened this issue Nov 1, 2019 · 6 comments
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@edica
Copy link

edica commented Nov 1, 2019

Describe the bug
Practicing through the tutorial below. Using useSoftDeletes, and the fields indicated created_at, updated_at and deleted_at. Everything is working fine. But when I do a search with "where()" it doesn't show deleted records. Already using "like()" shows all deleted ones as well. like() should also not show deleted ones?

https://codeigniter4.github.io/CodeIgniter4/tutorial/news_section.html

CodeIgniter 4 version
CodeIgniter-4.0.0-rc.3

Affected module(s)
Unknown

Expected behavior, and steps to reproduce if appropriate
Shows deleted register:

$model->orLike(['title' => $q, 'slug' => $q, 'body' => $q])->paginate(5)

Do not show deleted register:

$model->where("body", $q)->paginate(5)

Context

  • OS: MacOS
  • Web server MAMP
  • PHP version 7.3.8
@edica edica added the bug Verified issues on the current code behavior or pull requests that will fix them label Nov 1, 2019
@MGatner
Copy link
Member

MGatner commented Feb 18, 2020

@edica I wasn't able to replicate this issue. I have 4 Factories in the database all with "fas ..." icons, one with deleted_at set. I ran the following:

$factories = new \App\Models\FactoryModel();
$data = [
	'orLike' => $factories->orLike(['icon' => 'fas'])->paginate(5),
	'where' => $factories->where('id <', 4)->paginate(5),
];

orLike returned 3 of the 4 as expected, where returned 2 as expected.

Can you pull the latest develop branch and try again, in case it was some issue incidentally fixed along the way? If you are still having problems provide more context (like was the orLike following another where statement?).

You can also harvest the actual database queries generated from the Debug Toolbar. For example, from mine above:

0.89 ms | SELECT COUNT(*AS `numrows` FROM `dev_factories` WHERE `icon` LIKE '%fas%' ESCAPE '!' AND `dev_factories`.`deleted_at` IS NULL
0.95 ms | SELECT * FROM `dev_factories` WHERE `icon` LIKE '%fas%' ESCAPE '!' AND `dev_factories`.`deleted_at` IS NULL AND `dev_factories`.`deleted_at` IS NULL LIMIT 5
0.97 ms | SELECT COUNT(*AS `numrows` FROM `dev_factories` WHERE `id` < 4 AND `dev_factories`.`deleted_at` IS NULL
0.88 ms | SELECT * FROM `dev_factories` WHERE `id` < 4 AND `dev_factories`.`deleted_at` IS NULL AND `dev_factories`.`deleted_at` IS NULL LIMIT 5

@MGatner
Copy link
Member

MGatner commented Aug 25, 2020

No response from user.

@MGatner MGatner closed this as completed Aug 25, 2020
@Kelvin-te
Copy link

Am on CodeIgniter 4.3.3 and experiencing the same issue. orLike returns deleted records as well.

@markatsdp
Copy link

markatsdp commented Mar 22, 2024

@MGatner Same thing on 4.4.5.

@kenjis
Copy link
Member

kenjis commented Mar 22, 2024

Check the SQL statement that are generated in the Debug Toolbar.

@markatsdp
Copy link

@kenjis Thanks for the tip. It seems that the like() and orLike() statements are not grouped together when the deleted_at is present. I had to explicitly group them together.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

No branches or pull requests

5 participants