我在Cake错误的地方遇到问题:(
我有三个表格 - CC_PLAYLIST
,CC_PLAYLISTCONTENTS
和CC_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_PLAYLISTCONTENTS
和CC_FILES
之间的联接不是很好。 CC_PLAYLISTCONTENTS
应CC_FILES
加入CC_PLAYLISTCONTENTS
。file_id
= CC_FILES
。id
,但似乎正在CC_PLAYLISTCONTENTS
。{{ 1}} = id
。CC_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'
));