Skip to content

Commit

Permalink
Allow "lazy" eager loading from an individual model: `$user->load('or…
Browse files Browse the repository at this point in the history
…ders.lines');`.
  • Loading branch information
taylorotwell committed Apr 11, 2013
1 parent 73efad9 commit 4612d11
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- Implement sectionable caching across all drivers which support incrmeent / decrement.
- Added `Redirect::home` method from Laravel 3.
- Added `Crypt::setKey`, `Crypt::setCipher`, and `Crypt::setMode`.
- Allow "lazy" eager loading from an individual model: `$user->load('orders.lines');`.

## Beta 4

Expand Down
13 changes: 13 additions & 0 deletions src/Illuminate/Database/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,19 @@ public static function findOrFail($id, $columns = array('*'))
throw new ModelNotFoundException;
}

/**
* Eager load relations on the model.
*
* @param dynamic string
* @return void
*/
public function load()
{
$query = $this->newQuery()->with(func_get_args());

$query->eagerLoadRelations(array($this));
}

/**
* Being querying a model with eager loading.
*
Expand Down

0 comments on commit 4612d11

Please sign in to comment.