valan Posted November 8, 2015 Posted November 8, 2015 Does 'sort' support subfields? I'm trying to sort pages like this: $query = 'template=mytemplate,sort=myfield.mysubfield'; $result = wire('pages')->find($query); It generates: Exception: SQLSTATE[42S22]: Column not found: 1054 Unknown column '_sort_myfield.mysubfield' in 'mytemplate clause' (in var/www/pw/wire/core/PageFinder.php line 298) E.g. is there any way to sort by subfields in a query?
LostKobrakai Posted November 8, 2015 Posted November 8, 2015 Is this subfield stored in the db or just runtime generated? When you're not using limit in the selector you could try to sort the result in memory after getting it from the db. 1
valan Posted November 8, 2015 Author Posted November 8, 2015 Is this subfield stored in the db or just runtime generated? This subfield is stored in db. When you're not using limit in the selector you could try to sort the result in memory after getting it from the db. Do you mean that this should work? Not sure but will give a try. $query = 'template=mytemplate'; $result = wire('pages')->find($query)->sort('myfield.mysubfield');
kongondo Posted November 9, 2015 Posted November 9, 2015 (edited) Andrey, sort by the real name of the database column (in your case it is 'data') and it will work, i.e. $query = 'template=mytemplate,sort=myfield.data';//data here = real name of the mysubfield, not its alias At the moment, I don't know how to tell sort to sort by the alias of a subfield...Searching using an alias (if set) works fine though, e.g. $p = $pages->get('template=mytemplate, myfield.mysubfield=whatever'); Edited November 9, 2015 by kongondo 1
valan Posted November 10, 2015 Author Posted November 10, 2015 kongondo, real name also doesn't work (( The same exception is generated: Exception: SQLSTATE[42S22]: Column not found: 1054 Unknown column '_sort_myfield_data.data' in 'mytemplate clause'
valan Posted November 10, 2015 Author Posted November 10, 2015 Ups... my mistake. Missed own syntax error. Closed. @kongondo, @LostKobrakai - thanks!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now