1
問題 我想獲取有關活動的信息以及其中的所有字符部分。但我也想要人物肖像。當我試圖做到這一點時,我得到的信息和人物,但不是肖像。Eloquent:嵌套關係返回null
運動模式
public function player_characters()
{
return $this->hasMany('Sagohamnen\Character\Character', 'campaign_id')->select('id','campaign_id', 'name', 'portrait_id')->where('characters.type', 1)->where('characters.status', 1);
}
人物模型
public function thumb_portrait()
{
return $this->belongsTo('Sagohamnen\Portrait\Portrait')->select('thumbnail', 'id');
}
能言善辯的查詢
return Campaign::select('id', 'genre', 'name', 'description',
'max_nr_players', 'rating', 'created_at', 'updated_at')->where('id',
$campaign_id)->with('player_characters.thumb_portrait')->first();
結果
string(139) "select `id`, `genre`, `name`, `description`, `max_nr_players`, `rating`, `created_at`, `updated_at` from `campaigns` where `id` = ? limit 1"
array(1) {
[0]=>
string(1) "1"
}
string(165) "select `id`, `campaign_id`, `name`, `portrait_id` from `characters` where `characters`.`type` = ? and `characters`.`status` = ? and `characters`.`campaign_id` in (?)"
array(3) {
[0]=>
int(1)
[1]=>
int(1)
[2]=>
int(1)
}
string(71) "select `thumbnail`, `id` from `portraits` where `portraits`.`id` in (?)"
array(1) {
[0]=>
int(0)
}
字DB-表
id - name - portrait_id
1 Gandalf 3
肖像DB-表
id - thumbnail
3 - http://wwww....