사용자 (ID, 이름, 이메일, ...) 영화 (ID, 이름, ...) users_watchlists (ID 266 movie_id)CakePHP의 구문 내가 관계를 다음과 같은 한 오류 또는 액세스 위반
그것의 HABTM 관계.
오류
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
.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
FROMreelstubs
.users
ASUsersWatchlist
JOINreelstubs
.users
ASUsersWatchlist
ON (UsersWatchlist
.movie_id
= 4 ANDUsersWatchlist
.user_id
=UsersWatchlist
.id
)Notice: If you want to customize this error message, create 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' => ''
)
);
UsersWatchlist
public $belongsTo = array(
'User' => array(
'className' => 'User',
'foreignKey' => 'user_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Movie' => array(
'className' => 'Movie',
'foreignKey' => 'movie_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
확실하지 이유는 당신이 UsersWatchlist
라는 관계 데이터 테이블의 모델을하고있는 사용자와 영화 사이의 관계라는 이름 때문에 UsersWatchlist
"이름"이 같은 두 개의 표가있는 것 같습니다. –
동일한 모델 구조로 다른 질문을 많이 올렸지 만 답변에 언급 된 수정 사항이 포함되어있는 것으로 나타났습니다. 내 대답이 당신을 도왔다 고 결론 지을 수 있습니까? – nIcO