確保您的HABTM協會正在設置正確(cake bake
會想到加入的jobs_users
,而不是users_jobs
表(見:Cakephp-HABTM)如果是這樣,在本例中改變JobsUser引用下面UsersJob匹配您所描述的佈局。
//In an action in jobs_controller.php
//Fake a HasOne association to the JobsUser model, setting $reset to false
$this->Job->bindModel(array(
'hasOne' => array(
'JobsUser'
)
), false);
//Setup the paginate conditions, grouping on job.id
//Set $user_id to the user to filter results by (can also be an array of users)
$options = array(
'group' => 'Job.id',
'conditions' => array(
'JobsUser.user.id' => $user_id
)
);
$this->paginate = $options;
$users = $this->paginate();
你能描述一下你的條件想這樣做,也說明哪些字段的結果集應包含 – OldWest 2011-02-09 02:27:45