pagination passing data

I am fetching all records having flag =1 from contacts table...

$contacts = Contacts::find('flag="'.$flag.'"');

$paginator = new Phalcon\Paginator\Adapter\Model(array(
"data" => $contacts,    //Data to paginate
"limit" => 30,           //Rows per page
"page" => $numberPage   //Active page

Now I want to fetch information from different table nameas mailcontacts having flag=1; $mailcontacts = MailContacts::find('flag="'.$flag.'"'); And Want to pass that mailcontacts data to contacts. Will it be possible in phalcon so that paginaion along with reset of the things should work.


If you have a relations between Contacts and MailContacts you can use:

foreach ($paginator->getPaginate()->items as $contact)  {
    echo $contact->getName();
    foreach ($contact->getMailsContacts(["$flag = ".$contact->getFlag()]) as $mc) {
       /// echo something ?