Skip to content
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

Roles->descendants() not working #89

Open
orinoco opened this issue Feb 28, 2017 · 6 comments
Open

Roles->descendants() not working #89

orinoco opened this issue Feb 28, 2017 · 6 comments

Comments

@orinoco
Copy link

orinoco commented Feb 28, 2017

With mysql >= 5.7, this does not work anymore - it returns an empty array (and hides the SQL error). The issue is with the GROUP BY clause, whose behaviour was changed with this update.

http://craftcms.stackexchange.com/questions/12084/getting-this-sql-error-group-by-incompatible-with-sql-mode-only-full-group-by

The easiest solution is to revert back to previous mysql behaviour, which can be accomplished by setting sql-mode to TRADITIONAL. This can be done at runtime globally, per session or at startup in a config file.

https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html

Easiest for me was to update my.cnf to contain sql_mode=TRADITIONAL under [mysqld], which removes the problematic ONLY_FULL_GROUP_BY mode.

Of course a better solution would be to update the SQL query.

@abesapien
Copy link

Nice find. I recommend submitting a patch as a merge request.

@abiusx
Copy link
Contributor

abiusx commented Apr 27, 2017 via email

@cw1427
Copy link

cw1427 commented Dec 4, 2018

reproduced this issue in mysql 5.7.24. Do we have plan to update the SQL query on descendantsConditional(...) function?

@abiusx
Copy link
Contributor

abiusx commented Dec 4, 2018 via email

@cw1427
Copy link

cw1427 commented Dec 4, 2018

The query should be something like this:
select node.*,(count(parent.id)-1 - (sub_tree.innerDepth)) as Depth from perm_roles as node, perm_roles as parent, perm_roles as sub_parent, (select node.id, (count(parent.id) -1) as innerDepth from perm_roles as node, perm_roles as parent where node.lft between parent.Lft and parent.rght and node.id =1 group by node.id order by node.lft) as sub_tree where node.lft between parent.lft and parent.rght and node.lft between sub_parent.lft and sub_parent.rght and sub_parent.id = sub_tree.id group by node.id having Depth >0

And below is the error.
ERROR 1055 (42000): Expression #6 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'sub_tree.innerDepth' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

Yeah, I'm trying to take a deep look at it.

@cw1427
Copy link

cw1427 commented Dec 4, 2018

Add a aggregrate function group_concat in the select list for fix:
#114

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants