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 8d ago

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



10.1k

U can show an example?

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

edited 8d ago

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
}