1
votes

I'm having problem to try eager loading polymorphic relation in Laravel 4.1. Please take a look at this: http://help.laravel.io/d1fb6a5b00975db6 … f037b002f4

Basically i tested non-polymorphic eager loading, and it works perfectly.

And if I tried this, it works:

Route::get('polytest', function ()
{
  $data = new \StdClass;
  $data->model = new \Picture;
  $posts = $data->model->find(1);
  $posts = $posts->authorable;
  //dd( DB::getQueryLog() );
  return $posts;
});

But this doesnt work:

Route::get('polytest', function ()
{
  $model = new \Picture;
  $posts = $model->with('authorable')
            ->orderBy('updated_at', 'desc')
            ->take(15)
            ->get();
  //dd( DB::getQueryLog() );
  return $posts;
});

PS: the related models and migrations are in the link above.

1

1 Answers

3
votes

AFAIK it's not yet available in Laravel 4.1 master branch but a fix is on the way, in an already submitted pull request.

Still, if you need it up and running at the moment, you can make use of the PR anyway. Check it out:

https://github.com/laravel/framework/pull/3038

For details, follow the original discussion here:

https://github.com/laravel/laravel/issues/1681

UPDATE:

As @ChristianMichael reports in a comment below, initial support for MorphTo eager loading has been just added in version 4.1.23 of Laravel, big up!