We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

group error[SOLVED]

When I try group

$user->getRequests(array('limit' => 3, 'order' => 'id DESC', 'group' => "country, resort, hotel"));

I got error

Phalcon\Mvc\Model\Exception: Scanning error before 'country, resort,...' when parsing: SELECT [Request\Entity\Request].* FROM [Request\Entity\Request] WHERE [customer_id] = ?0 GROUP BY [country, resort, hotel] ORDER BY id DESC LIMIT 3 (147)

Backtrace

#0  Phalcon\Mvc\Model\Query->parse()
#1  Phalcon\Mvc\Model\Query->execute(Array([0] => 8), null)
#2  Phalcon\Mvc\Model->find(Array([0] => [customer_id] = ?0, [bind] => Array([0] => 8), [di] => Object(Phalcon\DI\FactoryDefault), [limit] => 3, [order] => id DESC, [group] => country, resort, hotel))
#3  Phalcon\Mvc\Model\Manager->getRelationRecords(Object(Phalcon\Mvc\Model\Relation), null, Object(User\Entity\User: 23), Array([limit] => 3, [order] => id DESC, [group] => country, resort, hotel))
#4  Phalcon\Mvc\Model->_getRelatedRecords(User\Entity\User, getRequests, Array([0] => Array([limit] => 3, [order] => id DESC, [group] => country, resort, hotel)))
#5  Phalcon\Mvc\Model->__call(getRequests, Array([0] => Array([limit] => 3, [order] => id DESC, [group] => country, resort, hotel)))

But when

$user->getRequests(array('limit' => 3, 'order' => 'id DESC', 'group' => "country"));
//or
$user->getRequests(array('limit' => 3, 'order' => 'id DESC', 'group' => "resort"));

it works correctly.

In docs, I find “group” => “name, status”, but for me its not work.

@xAockd

Not sure but try to write it exactly as the doc does (without spaces after comas)



11.8k

@SneakyBobito

still not working



98.9k
Accepted
answer

Can you try?

->getRequests(array('limit' => 3, 'order' => 'id DESC', 'group' => array("country", "resort", "hotel")));


11.8k