Eager Loading from the model in Laravel 4
Asked Answered
P

1

9

In Laravel 3, one could do the following in the model (http://laravel.com/docs/database/eloquent#eager):

class Book extends Eloquent 
{
     public $includes = array('author');     // this line

     public function author()
     {
           return $this->belongs_to('Author');
     }
}

which was useful if loading the same models often.

In Laravel 4, adding "this line" doesn't seem to do cause eager loading though. It also doesn't seem to be mentioned in the docs (http://four.laravel.com/docs/eloquent#eager-loading).

Has it been replaced by something else or is this functionality simply gone?


Update:

I've looked at the source for model (so nice to read). It's now:

/**
 * The relations to eager load on every query.
 *
 * @var array
 */
protected $with = array();

Is there any way that I can suggest this to be added (back) to the documentation (it seems like one of those little things that can easily be overlooked)?

Punctual answered 4/4, 2013 at 23:15 Comment(0)
L
1

The docs are on github (https://github.com/laravel/docs) so you can do some requests...

Longlegged answered 5/4, 2013 at 7:11 Comment(1)
Thanks, I forked it and submitted a pull request. This is actually a lot easier than I thought :)Punctual

© 2022 - 2024 — McMap. All rights reserved.