Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
UserAdminV2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
庄欣
UserAdminV2
Commits
b28c5eb1
Commit
b28c5eb1
authored
Jul 02, 2012
by
Steven Lischer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
docs edit: eager loading using $includes in model
parent
603e349d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
0 deletions
+23
-0
laravel/documentation/database/eloquent.md
+23
-0
No files found.
laravel/documentation/database/eloquent.md
View file @
b28c5eb1
...
@@ -406,6 +406,28 @@ You may even eager load nested relationships. For example, let's assume our **Au
...
@@ -406,6 +406,28 @@ You may even eager load nested relationships. For example, let's assume our **Au
$books = Book::with(array('author', 'author.contacts'))->get();
$books = Book::with(array('author', 'author.contacts'))->get();
If you find yourself eager loading the same models often, you may want to use
**$includes**
in the model.
class Book extends Eloquent {
public $includes = array('author');
public function author()
{
return $this->belongs_to('Author');
}
}
**$includes**
takes the same arguments that
**with**
takes. The following is now eagerly loaded.
foreach (Book::all() as $book)
{
echo $book->author->name;
}
> **Note:** Using **with** will override a models **$includes**.
<a
name=
"constraining-eager-loads"
></a>
<a
name=
"constraining-eager-loads"
></a>
## Constraining Eager Loads
## Constraining Eager Loads
...
@@ -419,6 +441,7 @@ Sometimes you may wish to eager load a relationship, but also specify a conditio
...
@@ -419,6 +441,7 @@ Sometimes you may wish to eager load a relationship, but also specify a conditio
In this example, we're eager loading the posts for the users, but only if the post's "title" column contains the word "first".
In this example, we're eager loading the posts for the users, but only if the post's "title" column contains the word "first".
<a
name=
"getter-and-setter-methods"
></a>
<a
name=
"getter-and-setter-methods"
></a>
## Getter & Setter Methods
## Getter & Setter Methods
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment