0

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';

}
4

1 に答える 1

0

答えは簡単です。

エラーがありましたAppModel

そうだった:

public function __construct($id = false, $table = null, $ds = null) {
    parent::__construct();

でなければなりません:

public function __construct($id = false, $table = null, $ds = null) {
    parent::__construct($id, $table ,$ds);
于 2013-04-29T20:20:00.093 に答える