Jump to content

Recommended Posts

Posted
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?

Posted

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.

  • Like 1
Posted
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');
Posted (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 by kongondo
  • Like 1
Posted

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'

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...