我收到以下错误,无法理解原因。我可以看到PodcastsUser不是一个表...我用下面的DB烘焙了整个应用程序 -
我正好在访问/Podcasts/view/*Nr*
,index
等时收到错误。谢谢!
Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'PodcastsUser.podcast_id' in 'on clause'
SQL查询:
SELECT `User`.`id`, `User`.`email`, `User`.`password`, `PodcastsUser`.`users_id`, `PodcastsUser`.`podcasts_id`
FROM `podcaster`.`users`
AS `User`
JOIN `podcaster`.`podcasts_users`
AS `PodcastsUser`
ON (`PodcastsUser`.`podcast_id` = 1
AND `PodcastsUser`.`user_id` = `User`.`id`)
这是我的HABTM协会:
模型/ user.php的
public $hasAndBelongsToMany = array(
'Podcast' => array(
'className' => 'Podcast',
'joinTable' => 'podcasts_users',
'foreignKey' => 'user_id',
'associationForeignKey' => 'podcast_id',
'unique' => 'keepExisting',
)
);
模型/ Podcast.php
public $hasAndBelongsToMany = array(
'User' => array(
'className' => 'User',
'joinTable' => 'podcasts_users',
'foreignKey' => 'podcast_id',
'associationForeignKey' => 'user_id',
'unique' => 'keepExisting',
)
);
--- --- EDIT
PodcastsController view
操作:
public function view($id = null) {
if (!$this->Podcast->exists($id)) {
throw new NotFoundException(__('Invalid podcast'));
}
$options = array('conditions' => array('Podcast.' . $this->Podcast->primaryKey => $id));
$this->set('podcast', $this->Podcast->find('first', $options));
}