I have the following ratios Users (id, name, email address, ...) movies (id, name, ...) users_watchlists (id, user_id, movie_id)
His attitude is HABTM.
Error
Error: SQLSTATE [42000]: syntax error or access violation: 1066 Not unique table / alias: 'UsersWatchlist'
SQL Query: SELECT UsersWatchlist. id, UsersWatchlist. first_name, UsersWatchlist. last_name, UsersWatchlist. display_image, UsersWatchlist. email, 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. email, UsersWatchlist. password, UsersWatchlist. birthday, UsersWatchlist. gender, UsersWatchlist. group_id, UsersWatchlist. banned, UsersWatchlist. created, UsersWatchlist. modifiedFROM reelstubs. usersAS UsersWatchlistJOIN reelstubs. usersAS UsersWatchlistON (UsersWatchlist. movie_id= 4 And UsersWatchlist. user_id= UsersWatchlist. id)
Note. If you want to customize this error message, create an Application \ View \ Errors \ pdo_error.ctp
User model
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' => ''
)
);
Movie model
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' => ''
)
);
UsersWatchlist
public $belongsTo = array(
'User' => array(
'className' => 'User',
'foreignKey' => 'user_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Movie' => array(
'className' => 'Movie',
'foreignKey' => 'movie_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
Not sure why he is trying to get a name, etc. from UsersWatchlist