次の関係があります Users(id, name, email, ...) movies(id, name, ...) users_watchlists(id, user_id, movie_id)
HABTM 関係です。
エラー
エラー: SQLSTATE[42000]: 構文エラーまたはアクセス違反: 1066 一意でないテーブル/エイリアス: 'UsersWatchlist'
SQL クエリ: SELECT
UsersWatchlist.id、UsersWatchlist。first_name、UsersWatchlist。last_name、UsersWatchlist。display_image、UsersWatchlist。UsersWatchlist。password、UsersWatchlist。birthday、UsersWatchlist。gender、UsersWatchlist。group_id、UsersWatchlist。banned、UsersWatchlist。created、UsersWatchlist。modified、UsersWatchlist。id、UsersWatchlist。first_name、UsersWatchlist。last_name、UsersWatchlist。display_image、UsersWatchlist。UsersWatchlist。password、UsersWatchlist。birthday、UsersWatchlist。gender、UsersWatchlist。group_id、UsersWatchlist。banned、UsersWatchlist。created、UsersWatchlist。modifiedからreelstubs。usersASUsersWatchlistJOINreelstubs.usersそのままUsersWatchlist(UsersWatchlist.movie_id= 4 ANDUsersWatchlist.user_id=UsersWatchlist.id)注意: このエラー メッセージをカスタマイズする場合は、app\View\Errors\pdo_error.ctp を作成します。
ユーザーモデル
public $hasAndBelongsToMany = array(
'UsersWatchlist' => array(
'className' => 'Movie',
'joinTable' => 'users_watchlists',
'foreignKey' => 'user_id',
'associationForeignKey' => 'movie_id',
'unique' => 'keepExisting',
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
)
);
映画モデル
public $hasAndBelongsToMany = array(
'UsersWatchlist' => array(
'className' => 'User',
'joinTable' => 'users_watchlists',
'foreignKey' => 'movie_id',
'associationForeignKey' => 'user_id',
'unique' => 'keepExisting',
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
)
);
ユーザーウォッチリスト
public $belongsTo = array(
'User' => array(
'className' => 'User',
'foreignKey' => 'user_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Movie' => array(
'className' => 'Movie',
'foreignKey' => 'movie_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
UsersWatchlist から名前などを取得しようとしている理由がわからない