Support the ongoing development of Laravel.io →
posted 6 years ago
Eloquent
Last updated 1 year ago.
0

Maybe try to turn on logging of SQL queries and check if they are OK.

Eloquent/Query builders are great for 99% of things that you want to do with the database but throw in anything that's not "standard" and you will get a lot of wtfs

0

Thanks, Mike. I'll go ahead and try that. It's a good suggestion - I usually rely on debugbar to check my queries, but since it didn't get through, it failed.

Also, in my apply() method, I already tried a dd($builder->toSql()); right after addding the whereAs condition, but that didn't give me any output, so to be honest, I believe it's even before that - sounds like I'll have to dig into the query builder code to find out what's happening that is preventing my statement to execute.

Just for my sanity - what I wrote above seemed correct to you?

0

From the snippets you've posted it does seem correct to me and it works with simple $builder->where() so the problem is not with adding global scopes or the trait since it is getting booted.

I would bet on morphing or simple mistake like wrong column in where's. Also did you try to build the query outside of the global scopes? For example in tinker or just to test it in controller?

Anyway could you post your tables?

0

Sigh - I just found some issues on githbub that confirm this is not supported. There is no support for doing whereHas on morphTo relations.

It probably makes sense, because a morphTo can morph to different models, and the filter you add may not work for all related models, but I think we should be able to fix it though.

I'm going to look into it a bit more, and see if I could create a PR, or find a decent (alternative) solution for now.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

denjaland denjaland Joined 5 Dec 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.