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
78920c5d
Commit
78920c5d
authored
Jul 12, 2012
by
Franz Liedke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move automatic relationship parsing to Eloquent's query class.
parent
8c2a4fba
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
22 deletions
+30
-22
laravel/database/eloquent/model.php
+2
-20
laravel/database/eloquent/query.php
+28
-2
No files found.
laravel/database/eloquent/model.php
View file @
78920c5d
...
...
@@ -257,7 +257,7 @@ abstract class Model {
{
$includes
=
(
array
)
$includes
;
$
given_
includes
=
array
();
$
this
->
includes
=
array
();
foreach
(
$includes
as
$relationship
=>
$constraints
)
{
...
...
@@ -269,27 +269,9 @@ abstract class Model {
list
(
$relationship
,
$constraints
)
=
array
(
$constraints
,
null
);
}
$
given_
includes
[
$relationship
]
=
$constraints
;
$
this
->
includes
[
$relationship
]
=
$constraints
;
}
$relationships
=
array_keys
(
$given_includes
);
$implicits
=
array
();
foreach
(
$relationships
as
$relationship
)
{
$parts
=
explode
(
'.'
,
$relationship
);
$prefix
=
''
;
foreach
(
$parts
as
$part
)
{
$implicits
[
$prefix
.
$part
]
=
null
;
$prefix
.=
$part
.
'.'
;
}
}
// Add all implicit includes to the explicit ones
$this
->
includes
=
$given_includes
+
$implicits
;
return
$this
;
}
...
...
laravel/database/eloquent/query.php
View file @
78920c5d
...
...
@@ -127,7 +127,7 @@ class Query {
if
(
count
(
$results
)
>
0
)
{
foreach
(
$this
->
model
->
includes
as
$relationship
=>
$constraints
)
foreach
(
$this
->
model
_includes
()
as
$relationship
=>
$constraints
)
{
// If the relationship is nested, we will skip loading it here and let
// the load method parse and set the nested eager loads on the right
...
...
@@ -196,7 +196,7 @@ class Query {
{
$nested
=
array
();
foreach
(
$this
->
model
->
includes
as
$include
=>
$constraints
)
foreach
(
$this
->
model
_includes
()
as
$include
=>
$constraints
)
{
// To get the nested includes, we want to find any includes that begin
// the relationship and a dot, then we will strip off the leading
...
...
@@ -211,6 +211,32 @@ class Query {
}
/**
* Get the eagerly loaded relationships for the model.
*
* @return array
*/
protected
function
model_includes
()
{
$relationships
=
array_keys
(
$this
->
model
->
includes
);
$implicits
=
array
();
foreach
(
$relationships
as
$relationship
)
{
$parts
=
explode
(
'.'
,
$relationship
);
$prefix
=
''
;
foreach
(
$parts
as
$part
)
{
$implicits
[
$prefix
.
$part
]
=
NULL
;
$prefix
.=
$part
.
'.'
;
}
}
// Add all implicit includes to the explicit ones
return
$this
->
model
->
includes
+
$implicits
;
}
/**
* Get a fluent query builder for the model.
*
* @return Query
...
...
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