Welcome Guest, Not a member yet? Register   Sign In
orWhere query shows soft deleted entries
#1

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
Reply
#2

(This post was last modified: 01-08-2024, 08:05 AM by demyr.)

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
Reply
#3

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

(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()...
Reply
#5

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".
Reply
#6

(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.....
Reply




Theme © iAndrew 2016 - Forum software by © MyBB