I have a problem with HABTM in Cakephp.
There is two models: User (musicians) and Genre. And there is three tables: users, genres, genres_users (id (primary), genre_id, user_id).
Wrote in User:
<?php
public $hasAndBelongsToMany = array(
'Genre' => array(
'className' => 'Genre',
'joinTable' => 'genres_users',
'foreignKey' => 'user_id',
'associationForeignKey' => 'genre_id',
),
);
But as result i'm getting "Missing Database Table". What am I doing wrong?
Thanks.
upd User model
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',
),
);
}
Genre model:
class Genre extends AppModel {
public $primaryKey = 'id';
}