Cakephp の HABTM に問題があります。
ユーザー(ミュージシャン)とジャンルの2つのモデルがあります。また、ユーザー、ジャンル、ジャンル_ユーザー (id (プライマリ)、ジャンル_id、ユーザー_id) の 3 つのテーブルがあります。
ユーザーで書いた:
<?php
public $hasAndBelongsToMany = array(
'Genre' => array(
'className' => 'Genre',
'joinTable' => 'genres_users',
'foreignKey' => 'user_id',
'associationForeignKey' => 'genre_id',
),
);
しかし、その結果、「Missing Database Table」が表示されます。私は何を間違っていますか?
ありがとう。
ユーザーモデルの更新
class User extends AppModel {
public $primaryKey = 'id';
public $hasOne = array(
'PerformerProfile' => array(
'className' => 'PerformerProfile',
'dependent' => false,
),
'OrganizerProfile' => array(
'className' => 'OrganizerProfile',
'dependent' => false,
),
);
public $hasAndBelongsToMany = array(
'Genre' => array(
'className' => 'Genre',
'joinTable' => 'genres_users',
'foreignKey' => 'user_id',
'associationForeignKey' => 'genre_id',
'unique' => 'keepExisting',
),
);
}
ジャンル機種:
class Genre extends AppModel {
public $primaryKey = 'id';
}