-
Notifications
You must be signed in to change notification settings - Fork 66
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
Possibility to use HAVING instead of WHERE everywhere #26
Comments
Hi @royduin, Firstly, sorry for taking such a long time to get back to you. I don't think that having Potentially, using something like the Strategy pattern (https://github.com/domnikl/DesignPatternsPHP/tree/master/Behavioral/Strategy) to define how the queries are built might be a little better then an if statement. This way, a strategy can be included by default by the constructor method, and then if a new one is desired, it can be set (by calling This removes the requirement to have a large amount of parameters inside the constructor (which is good, IMHO. We should not have too many parameters, because it means the class does not really have a single responsibility). Wheres might still be able to work with your subquery, if you select them into a temporary table and perform the ie, for a simplistic example something like:
would be turned into
where your queries could then be added to the |
Hi @timgws, thanks for your response. I'm currently using your suggestion but in comparison with "having" it's very slow. For other people coming by here, I'm using this to do that in Laravel 5.5:
I'll update my PR asap with your suggestion and hope I find some time shortly to implement "having" on all places. |
Hi, I am encountering same need, Is there any update on this topic? |
See #27 |
I used this as a solution as you mentioned
I tried to override the package with your code #27 but It doesn't work as expected when using nested groups, for example Thanks |
Could you please email me (or include in this issue) a good example of how you are using the QueryBuilder, and why having (heh!) support for Just trying to work out a good way that this can be integrated into this project. As I understand MySQL, the Are the |
Hi My question was related on having an alias on my query then I cannot use WHERE anymore but HAVING. My solution was like @royduin suggested to put the query inside another query and then I can use WHERE again. Example query: In this case cannot use WHERE width > 0
Solution like mentioned above:
|
Got a not a clean solution but works more efficiently. The idea is in the were using the subselect instead of the alias in the HAVING statement. STEPS:
And works. Definitely, a Short-term solution, looking for something cleaner for the future. |
I let my users create their own subqueries which can be used as filters in the query builder. But wheres are not working with values from subqueries so I need this one to be
$query->having()
instead of$query->where()
. But inQBPFunctions.php
and inJoinSupportingQueryBuilderParser.php
there are some more wheres which should change in that case.Maybe a new parameter in the constructor?
The text was updated successfully, but these errors were encountered: