tags:

views:

8

answers:

1

hi, got this situation. Reports habtm users. So im trying to paginate just the Reports that are linked to the Auth user... I read when you have a habtm relationship you have to bind the model temporarily using 'hasOne' like this:

funtion index(){
$conditions=array('ReportsUser.user_id'=>$this->Auth->User('id'), 'ReportsUser.report_id'=>'Report.id');
$this->beforeFind();
$this->Report->recursive=0;
$this->set('reports',$this->paginate($conditions));
}

funtion beforeFind()
{
$this->Report->bindModel('hasOne'=>array('ReportsUser'), false);
}

so here is the issue... that doesn't work... that give me no results... I already checked the database for user having any Report, and i logged in with one of those user...

any suggestions?

A: 

GOT IT!!

$conditions=array('ReportsUser.user_id'=>$this->Auth->User('id'), 'ReportsUser.report_id'=>'Report.id'); 

i just had to remove 'ReportsUser.report_id'=>'Report.id' cuz cake was searching for it for a second time... so i just left

$conditions=array('ReportsUser.user_id'=>$this->Auth->User('id')); 

and i add

$this->Report->bindModel('hasOne'=>array('ReportsUser'**=>array('className'=>'ReportsUser', 'foreignKey'=>'report_id')**), false);
juan