CodeIgniter Forums
orWhere query shows soft deleted entries - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: orWhere query shows soft deleted entries (/showthread.php?tid=89097)



orWhere query shows soft deleted entries - Gehasi - 01-08-2024

Hi I have the following problem with my query. It shows also the entries from my database which are soft deleted. In the deleted_at there is a date and time but it is still shown in the results. Here is my query maybe Im doing something wrong. Thanks for helping me....
Code:
$data["offeneAnfragen"] = $this->work->where("genehmigt is null", Null)->orWhere('genehmigt', 0)->join("user", "user.id = urlaub.user_id ")->orderBy("user_id")->findAll();

Thanks


RE: orWhere query shows soft deleted entries - demyr - 01-08-2024

Why don't you use two ->where-s but orWhere? Or is or.  But 2-where means and.

Where

orWhere (on the same page actually)

Additionally, you can group your where lines for a cleaner look


RE: orWhere query shows soft deleted entries - kilishan - 01-08-2024

Just to confirm - in your model, have you set usesoftdeletes = true;?


RE: orWhere query shows soft deleted entries - Gehasi - 01-09-2024

(01-08-2024, 08:07 AM)kilishan Wrote: Just to confirm - in your model, have you set usesoftdeletes = true;?

yes it's set to true. and the problem is only there when I use orWhere()...


RE: orWhere query shows soft deleted entries - kilishan - 01-09-2024

Then doing the grouping that @demyr suggested is what you'll probably need to do.

I think what's happening is that the final query is saying "genehmigt is null or "genehmigt is 0 or deleted at is null". Grouping it would get you "(genehmigt is null or "genehmigt is 0) AND deleted at is null".


RE: orWhere query shows soft deleted entries - Gehasi - 01-10-2024

(01-09-2024, 07:57 AM)kilishan Wrote: Then doing the grouping that @demyr suggested is what you'll probably need to do.

I think what's happening is that the final query is saying "genehmigt is null or "genehmigt is 0 or deleted at is null". Grouping it would get you "(genehmigt is null or "genehmigt is 0) AND deleted at is null".

It worked with grouping thanks for the help to everyone.....