【发布时间】:2014-02-24 13:34:07
【问题描述】:
尝试预先加载模型及其相关模型,但相关模型返回 null,即使它具有相关数据。
组模型对 Game 或 Gamer 具有 1:1 的多态性。
组模型关系:
public function groupable()
{
return $this->morphTo();
}
游戏模型关系:
public function group()
{
return $this->morphOne('Group', 'groupable');
}
玩家模型关系:
public function group()
{
return $this->morphOne('Group', 'groupable');
}
查询加载组然后游戏:
$group = Group::whereSubdomain($id)->first();
$game = $group->game;
组返回组,但游戏返回 null。
这是 Groups 表的示例数据库条目:
id subdomain groupable_id groupable_type
5 Starmade 10 Game
这是 Games 表的示例数据库条目:
id genre rating
10 7 4.5
不知道我哪里错了没有游戏返回。
【问题讨论】:
标签: php laravel laravel-4 eager-loading