我有以下关系用户(id,名称,电子邮件,...)电影(id,名称,...) users_watchlists(id,user_id,movie_id)
它是HABTM关系。
错误
错误:SQLSTATE [42000]:语法错误或访问冲突:1066 不是唯一的表/别名:'UsersWatchlist'
SQL 查询:选择
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
。users
作为UsersWatchlist
加入reelstubs
。users
如UsersWatchlist
开(UsersWatchlist
.movie_id
= 4 和UsersWatchlist
。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 中获取名称等