0

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: enter image description here

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));
}
dh762
  • 2,259
  • 4
  • 25
  • 44
  • If it's just in that particular view, maybe the problem is how you're retrieving the object. Can you post the view action code? – Nunser Jun 20 '13 at 20:20
  • the same happens when I want to access `/users/view/1` (so, the User Model). – dh762 Jun 20 '13 at 20:27

0 Answers0