Jaxel Well-known member Jan 13, 2020 #1 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?
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?
Jeremy P XenForo developer Staff member Jan 23, 2020 #3 Jeremy P said: 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(); Click to expand... You should be able to adapt this pretty easily.
Jeremy P said: 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(); Click to expand... You should be able to adapt this pretty easily.
Jaxel Well-known member Jan 27, 2020 #4 Jeremy P said: You should be able to adapt this pretty easily. Click to expand... I've been unable to get this working... expression does not exist in the finder system.
Jeremy P said: You should be able to adapt this pretty easily. Click to expand... I've been unable to get this working... expression does not exist in the finder system.
Jeremy P XenForo developer Staff member Jan 27, 2020 #5 You'd have to post code, this works fine for me:
Jaxel Well-known member Jan 27, 2020 #6 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();
Lukas W. Well-known member Jan 28, 2020 #7 Jaxel said: 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(); Click to expand... 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.
Jaxel said: 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(); Click to expand... 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.