Hello i have relationship db model.
use Phalcon\Mvc\Model;
class A extends Model
{
public function initialize()
{
$this->belongsTo(
'b_id',
B::class,
'id',
[
'reusable' => true,
'alias' => 'B'
]
);
$this->belongsTo(
'c_id',
C::class,
'id',
[
'reusable' => true,
'alias' => 'C'
]
);
}
}
use Phalcon\Mvc\Model;
class B extends Model
{
public function initialize()
{
$this->hasMany(
'id',
A::class,
'b_id',
[
'reusable' => true,
'alias' => 'A'
]
);
}
}
use Phalcon\Mvc\Model;
class C extends Model
{
public function initialize()
{
$this->hasMany(
'id',
A::class,
'C_id',
[
'reusable' => true,
'alias' => 'A'
]
);
}
}
A model belongs to B and C.
I am trying to paginate A model datas.
use Phalcon\Paginator\Adapter\Model as PaginatorModel;
// Passing a resultset as data
$paginator = new PaginatorModel(
[
'model' => A::class,
'limit' => $count,
'page' => $page,
]
);
$paginate = $paginator->paginate();
"paginate" method returns to array (inside model->toArray()), how I can access to B and C model and properties in A with model based. I know, I can use queryBuilder or inside to foreach I can call B and C model with "findFirst"
this code not working because of returning array.
foreach ($paginate->getItems() as $a) {
$data[] = [
'a' => $a,
'b' => $a->b,
'c' => $a->c
];
}