I'm getting the following error and can't see why. I can see that the PodcastsUser is not a table... I baked the whole application with the DB below –
Im getting the error just when accessing/Podcasts/view/*Nr*
, index
etc is fine. THANK YOU!
Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'PodcastsUser.podcast_id' in 'on clause'
SQL Query:
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`)
this is my HABTM-association:
Model/User.php
public $hasAndBelongsToMany = array(
'Podcast' => array(
'className' => 'Podcast',
'joinTable' => 'podcasts_users',
'foreignKey' => 'user_id',
'associationForeignKey' => 'podcast_id',
'unique' => 'keepExisting',
)
);
Model/Podcast.php
public $hasAndBelongsToMany = array(
'User' => array(
'className' => 'User',
'joinTable' => 'podcasts_users',
'foreignKey' => 'podcast_id',
'associationForeignKey' => 'user_id',
'unique' => 'keepExisting',
)
);
---EDIT---
The PodcastsController view
action:
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));
}