Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eager Loading from the model in Laravel 4

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)?

like image 833
Ben Avatar asked Apr 04 '13 23:04

Ben


1 Answers

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

like image 51
Rob Gordijn Avatar answered Sep 20 '22 18:09

Rob Gordijn