I have this model code:
class TvguideChannel extends Model{
public function initialize() {
$this->setSource('tvguide_channel');
$this->setConnectionService('db');
$this->hasMany('code', __NAMESPACE__.'\Tvguide', "ch_code", ['alias' => 'Tvguide']);
}
public function getSource() {
return 'tvguide_channel';
}
}
And Controller:
$data = TvguideChannel::find();
$dateDetails = $data->getTvguide(['order' => '$_POST["time"] DESC']);
$paginator = new PaginatorModel(
array(
"data" => $data,
"limit" => $limit,
"page" => $curPage
)
);
$items = $paginator->getPaginate();
This is not working. How I Can use columns from Tvguide model in controller? Thanks for help.
Your controller code will return a
TvguideChannelinstance. To access the relation you have to use the alias you defined above.The above should contain all Tvguide's for this record.
Here is a more detailed example of
hasMany():UPDATE: example of passing parameters to the relation itself.
Model code:
Controller code:
UPDATE 2
find()method returns a Resulset, which means you can not use directly$data->getTvguide. You have to iterate over each record and access its related entries.