首页 文章

许多人在Laravel 4中充满了热情

提问于
浏览
1

我有这个型号:

class Ownership extends Eloquent {
    protected $table = 'game_user';

    public function games() {
        return $this->belongsToMany('Game');
    }

    public function type() {
        return $this->belongsToMany('owntype');
    }
}

GameOwntype 的型号很简单 ...extends Eloquent . 这是我拉取数据的方式:

$games = Ownership::with('games','type')->where('user_id','=','1')->get();

从理论上讲,它有效 . 实际上,不是,因为它返回空 gamesowntype 集合 . 这是它返回的内容:http://paste.laravel.com/s94

如何获取 gamesusers 表格内容?我不想在foreach中使用 Game::find ,因为它会产生很多查询 .

1 回答

  • 0

    你需要在 with() 内传递一个数组 .

    $games = Ownership::with(array('games','type'))->where('user_id','=','1')->get();
    

相关问题