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

How extend model method query?

Base construction

Model::query()
    ->inWhere('id', [])
    ->execute()
;

need add custom method

Model::query()
    ->inWhere('id', [])
    ->execute()
    ->getByIndex('id')
;

How add it?

edited Aug '17

By creating your own criteria class and setting it in di as Phalcon\\Mvc\\Model\\Criteria key



25.0k

U can show an example?

By creating your own criteria class and setting it in di as Phalcon\\Mvc\\Model\\Criteria key

edited Aug '17

Oh nvm i missed you want to do it after execute method. So from phalcon 3.1 you can set your custom class for resultset, just do something like:

class MyResultset extends Phalcon\Mvc\Model\Resultset\Simple
{
    public function getByIndex($column)
    {
        // do whatever here you need
    }
}

And in your model:

public function getResultsetClass()
{
    return MyResultset::class
}