0

我收到以下错误,不明白为什么。我可以看到 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 协会: 在此处输入图像描述

模型/用户.php

public $hasAndBelongsToMany = array(
    'Podcast' => array(
        'className' => 'Podcast',
        'joinTable' => 'podcasts_users',
        'foreignKey' => 'user_id',
        'associationForeignKey' => 'podcast_id',
        'unique' => 'keepExisting',
    )
);

模型/播客.php

    public $hasAndBelongsToMany = array(
    'User' => array(
        'className' => 'User',
        'joinTable' => 'podcasts_users',
        'foreignKey' => 'podcast_id',
        'associationForeignKey' => 'user_id',
        'unique' => 'keepExisting',
    )
);

---编辑--- 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));
}
4

0 回答 0