CakePHP多维模型 - 加入错误的地方

时间:2015-07-13 15:59:18

标签: php cakephp

我在Cake错误的地方遇到问题:(

我有三个表格 - CC_PLAYLISTCC_PLAYLISTCONTENTSCC_FILES

我希望获得所有播放列表的列表及其所有内容,然后是每个播放列表内容的相关文件信息。

Playlist 1
-- Playlist Content 1
---- File Info
-- Playlist Content 2
---- File Info
-- Playlist Content 3
---- File Info
Playlist 2
-- Playlist Content 123
---- File Info

在我的模型(AirtimePlaylist)中,我使用

获取此数据
$result = $this->find('all', array(
    'contain' => array(
        'AirtimePlaylistContent' => array(
            'fields' => array('AirtimePlaylistContent.id', 'AirtimePlaylistContent.playlist_id', 'AirtimePlaylistContent.file_id'),
            'AirtimeFile' => array(
                'fields' => array('AirtimeFile.id', 'AirtimeFile.track_title', 'AirtimeFile.artist_name')
            )
        ),
    ),
    'conditions' => array('AirtimePlaylist.id' => 5),
    'fields' => 'AirtimePlaylist.id', 'AirtimePlaylist.name'
));

然而,似乎CC_PLAYLISTCONTENTSCC_FILES之间的联接不是很好。 CC_PLAYLISTCONTENTSCC_FILES加入CC_PLAYLISTCONTENTSfile_id = CC_FILESid,但似乎正在CC_PLAYLISTCONTENTS。{{ 1}} = idCC_FILES

AirtimePlaylist.php

id

AirtimePlaylistContent.php

class AirtimePlaylist extends AppModel {

    public $useTable = 'cc_playlist';

    public $actsAs = array('Containable');
    public $hasMany = array('AirtimePlaylistContent' => array(
        'className' => 'AirtimePlaylistContent',
        'foreignKey' => 'playlist_id'
    ));

AirtimeFile.php

class AirtimePlaylistContent extends AppModel {

    public $useTable = 'cc_playlistcontents';

    public $hasOne = array('AirtimePlaylist' => array(
        'className' => 'AirtimePlaylist',
        'foreignKey' => 'id'
    ),'AirtimeFile' => array(
        'className' => 'AirtimeFile',
        'foreignKey' => 'id'
    ));

0 个答案:

没有答案