Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

How to combine 2 data sets into one paginator

Hi, everyone ! I try to comebine 2 data sets into one paginator. For example:

$result1 = modelName1::find();

$result2 = modelName2::find();

$result = $result1 + $result2;

$paginator = new Phalcon\Paginator\Adapter\Model(array( "data" => $result, "limit" => 12, "page" => $numberPage ));

Could anyone help me to do that? Thank you very much !

edited Mar '15

You have two options: you could make a phql sintax to get merged resultset, for example:

this code in model

    public function getMergedResultSet()
    {
            $phql = "SELECT
                              model1.col1,
                              model1.col2,
                              model2.col1,
                              model2.col2
                           FROM
                              model1,
                              model2
            ";
            $query = $this->getDi()->getShared("modelsManager")->createQuery($phql);

            return $query->execute();
    }

for execute modelsManager phql you should add the next syntax in bootstrap file DI:

$di = new Phalcon\DI();

$di->set('modelsManager', function() { return new Phalcon\Mvc\Model\Manager(); });

other option is array_merge function, but i like the first.