Is it a bug in CakePHP - Sort Aliases?

0

I'm trying to sort a query by relevance with cakephp using paginator, but it simply ignores the alias, I already researched the manual but so far I have not found the solution, the query works perfectly, when I give a debug it generates the query below, but the order by does not appear see:

    SELECT *, MATCH ('titulo','conteudo') AGAINST ('e-mail marketing' IN BOOLEAN MODE) AS relevance, MATCH ('titulo') AGAINST ('e-mail marketing' IN BOOLEAN MODE) AS title_relevance FROM 'db_forum'.'ra_forum' AS 'Forum' WHERE MATCH (titulo,conteudo) AGAINST ('e-mail marketing' IN BOOLEAN MODE) LIMIT 10

Follow the code:

$this->paginate = array(

                'fields'     => array('*', "MATCH ('titulo','conteudo') AGAINST ('$q' IN BOOLEAN MODE) AS relevance,  MATCH ('titulo') AGAINST ('$q' IN BOOLEAN MODE) AS title_relevance"),
                'conditions' =>  "MATCH ('titulo','conteudo') AGAINST ('$q' IN BOOLEAN MODE)",
                'order'      => array( 'relevance' => 'desc', 'title_relevance' => 'desc'),
                'limit'      => 10
        );

Is it any good for this to work?

Edit:

asked by anonymous 24.05.2014 / 00:43

1 answer

1

Correct is to ally the model to the field.

array(
    'conditions' => array('Model.field' => $thisValue), //array of conditions
    'recursive' => 1, //int
    //array com os campos
    'fields' => array('Model.field1', 'DISTINCT Model.field2'),
    //string(1 campo) ou array(mais de 1 campo)
    'order' => array('Model.created', 'Model.field3 DESC'),
    'group' => array('Model.field'), //fields to GROUP BY
    'limit' => n, //int
    'page' => n, //int
    'offset' => n, //int
    'callbacks' => true //ou false, 'before', 'after'
);

link

This rule also applies to PaginatorComponent

You can use this answer: Pagination always shows 20 images

    
30.05.2014 / 13:03