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
Unknown generated column in 'having clause' when findAndCountAll #4782
Comments
|
I've seen a similar problem in another framework/language before. For that specific case, the solution was to have the count part using a subquery instead of just |
@straube There's not great support for subqueries in sequelize currently. Could you show an example of how that query would look? |
@janmeier Using the query @jjacquesf posted, the count query should look something like: SELECT COUNT(*) FROM (
SELECT `Id`, `status`, ( 6371 * acos( cos( radians(20.6596988) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(-103.34960920000003) ) + sin( radians(20.6596988) ) * sin( radians( lat ) ) ) ) AS `distance` FROM `Billboards` AS `Billboard` HAVING `distance` < 5
) AS `sub`; We need to keep the columns in the subquery because they may be used by |
@mickhansen - I actually found out that you can use your attributes in such queries (having, etc...). Notice that I've put 'distance' in the brackets, sequelize just prints this out as
This can be closed. |
@jamesone By brackets (
and
However, if you're definitely talking about the brackets, @jjacquesf used in the exact same syntax you mentioned – refer to the first comment. And it didn't work. |
I was running a similar query (making calculation in attribute, named it distance), the only way to reference that value in my having: clause was to put single quotes around it (probably works with double aswell), I'm pretty sure Sequelize tried to look for the column distance in my model and then just defaulted to 'distance in my query' Sent from Outlook On Fri, Apr 15, 2016 at 4:02 AM -0700, "Gustavo Straube" notifications@github.com wrote: @jamesone By brackets ({ and }) you mean single quotes or apostrophes (')? If so, maybe I'm wrong, but I don't think that make any difference in the runtime. Both snippets below, although the slightly different syntax, give the same result: 'distance': { and distance: { However, if you're definitely talking about the brackets, @jjacquesf used in the exact same syntax you mentioned – refer to the first comment. And it didn't work. — |
@jamesone did you get any solutions ? I am also facing same issue |
This may Help:
|
I'm facing the same issue. Did something change in this topic? |
Not working for me neither, tried all the solutions you mentioned... :/ |
I am also facing same issue please help me out if anyone got the solution |
This issue has been automatically marked as stale because it has been open for 14 days without activity. It will be closed if no further activity occurs within the next 14 days. If this is still an issue, just leave a comment or remove the "stale" label. 🙂 |
7 years and I keep coming back. |
I am facing the same issue. is there something new ? |
I am trying to get back rows and count with specific
Query executed by Sequelize in findAll:
Query executed by Sequelize in findAndCountAll:
Result:
The text was updated successfully, but these errors were encountered: