1

这是一个歌曲和歌词数据库。我正在尝试从我的数据库中烘焙一个应用程序,它看起来像这样:(每个表都有一个 ID,我只是把它省略了......)

songs
    song_name

artists
    artist_name

songs_singers
    artist_id (FOREIGN KEY artists.id)
    song_id (FOREIGN KEY songs.id)

songs_writers
    artist_id (FOREIGN KEY artists.id)
    song_id (FOREIGN KEY songs.id)

song_views
    song_id (FOREIGN KEY songs.id)

videos
    song_id (FOREIGN KEY songs.id)

video_views
    video_id (FOREIGN KEY videos.id)

作家和歌手都是重叠的,即有的作家唱歌,有的歌手写作。

当我烘焙歌曲表时,我收到此错误: 错误:模型 Singer 的表歌手未在数据源默认值中找到。

我认为问题在于 CakePHP 想要我为歌手创建一个新模型,所以我最终不得不在一个新的表歌手中复制作家和歌手的名字。我只想要存储在艺术家中的名称,并且将 song_singers 和 song_writers 都链接到具有外键 ID 的表。

歌曲有很多:

  • 意见

  • 视频

视频有很多:

  • 意见

作家和歌手都有很多:

  • 歌曲

我应该怎么办?

编辑:这是模型 SongsSinger。


class SongsSinger extends AppModel {

public $validate = array(
    'song_id' => array(
        'numeric' => array(
            'rule' => array('numeric'),
            //'message' => 'Your custom message here',
            //'allowEmpty' => false,
            //'required' => false,
            //'last' => false, // Stop validation after this rule
            //'on' => 'create', // Limit validation to 'create' or 'update' operations
        ),
    ),
    'artist_id' => array(
        'numeric' => array(
            'rule' => array('numeric'),
            //'message' => 'Your custom message here',
            //'allowEmpty' => false,
            //'required' => false,
            //'last' => false, // Stop validation after this rule
            //'on' => 'create', // Limit validation to 'create' or 'update' operations
        ),
    ),
);


public $belongsTo = array(
    'Song' => array(
        'className' => 'Song',
        'foreignKey' => 'song_id',
        'conditions' => '',
        'fields' => '',
        'order' => ''
    ),
    'Artist' => array(
        'className' => 'Artist',
        'foreignKey' => 'artist_id',
        'conditions' => '',
        'fields' => '',
        'order' => ''
    )
);
}
4

1 回答 1

0

你没有任何歌手(你称他们为艺术家)。

您的数据库应该是:

songs_artists
    artist_id (FOREIGN KEY artists.id)
    song_id (FOREIGN KEY songs.id)
于 2013-02-26T18:12:33.747 回答