我使用三个表播放列表、entityAsset和playlistEntityAsset。播放列表实体资产表有2列playlist_id,asset_id指的是另外两个表。当我试图通过playlist_id获得数据过滤器时,它给我这个错误。
SQLSTATE[42S22]:未找到列:1054未知列“播放列表\实体\资产”。“where子句”中的“play\u list\u id”(SQL:select*fromplaylist\u entity\u assets
whereplaylist\u entity\u assets
play\u list\u id
=3和playlist\u entity\u assets
不为空)
这是我的获取方法。即使我的表有一个“playlist_id”列。这个查询调用“play_list_id”列。
public function show($subdomain, $id) {
$universe = Auth::user()->getCurrentUniverse();
$playlist = PlayList::find($id);
//return empty responce
if( $playlist == null){
return Response::json();
}
$playlistAssets = array();
$playlistEntityAssets = $playlist->playlistEntityAssets;
foreach($playlistEntityAssets as $plEntityAsset){
$asset = $plEntityAsset->entityAsset;
$plAsset = ['asset' => $asset ];
$playlistAssets[] = $plAsset;
}
return Response::json($playlistAssets);
}
我想通过playlist_id在"playlistEntityAsset"表中安装所有enityAsset数据过滤器。
使用照明\数据库\雄辩\模型;
类PlayEntityAssets扩展模型{
protected $table = 'playlist_entity_assets';
public function user()
{
return $this->belongsTo('asset');
}
public function universe()
{
return $this->belongsTo('Universe');
}
public function playlist(){
return $this->belongsTo('Playlist', 'playlist_id');
}
public function entityAsset(){
return $this->belongsTo('EntityAsset', 'asset_id');
}
我已经解决了这个问题。答案是在播放列表模型中输入确切的列名。
class PlayList extends Eloquent{
public function playlistEntityAssets()
{
return $this->hasMany('PlaylistEntityAssets', 'playlist_id' );
}
}