XF 2.1 Is it possible to order a finder query by varchar length?

Jaxel

Well-known member
Code:
$this->finder('EWR\Carta:Page')
    ->order('page_name', 'ASC')
`

I have a simple query... but I would prefer to order it by CHAR_LENGTH(page_name) DESC first. How would I do this?
 
You can use a finder expression with order():

PHP:
$finder = \XF::finder('Vendor\Addon:Entity');
$entities = $finder
    ->order($finder->expresssion('FIELD(%s, 1, 2, 3)', 'column_name'))
    ->fetch();

You should be able to adapt this pretty easily.
 
Weird... this works:
Code:
        $finder = $this->finder('EWR\Carta:Page');
        $finder
            ->where('page_id', '!=', $page->page_id)
            ->orderTitle();

But this does not:
Code:
        $finder = $this->finder('EWR\Carta:Page')
            ->where('page_id', '!=', $page->page_id)
            ->orderTitle();
 
Weird... this works:
Code:
        $finder = $this->finder('EWR\Carta:Page');
        $finder
            ->where('page_id', '!=', $page->page_id)
            ->orderTitle();

But this does not:
Code:
        $finder = $this->finder('EWR\Carta:Page')
            ->where('page_id', '!=', $page->page_id)
            ->orderTitle();

Sounds more like your finder method isn't returning the finder at the end, thus turning $finder into null, which isn't happening in the first block as you don't write it back.
 
Top Bottom