0

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:

function 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));
}

function 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?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
juan
  • 21
  • 4

1 Answers1

0

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
  • 21
  • 4