Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
syncEnrollments
Project
Project
Details
Activity
Releases
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yeray Santana Hualde
syncEnrollments
Commits
5c3ede74
Commit
5c3ede74
authored
Jul 24, 2012
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #946 from franzliedke/patch-23
Fix eager loading constraints
parents
764e7bc6
78920c5d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
23 deletions
+19
-23
model.php
laravel/database/eloquent/model.php
+8
-13
query.php
laravel/database/eloquent/query.php
+11
-10
No files found.
laravel/database/eloquent/model.php
View file @
5c3ede74
...
...
@@ -257,26 +257,21 @@ abstract class Model {
{
$includes
=
(
array
)
$includes
;
$
all_
includes
=
array
();
$
this
->
includes
=
array
();
foreach
(
$includes
as
$include
)
foreach
(
$includes
as
$relationship
=>
$constraints
)
{
$nested
=
explode
(
'.'
,
$include
);
$inc
=
array
();
foreach
(
$nested
as
$relation
)
// When eager loading relationships, constraints may be set on the eager
// load definition; however, is none are set, we need to swap the key
// and the value of the array since there are no constraints.
if
(
is_numeric
(
$relationship
))
{
$inc
[]
=
$relation
;
$all_includes
[]
=
implode
(
'.'
,
$inc
);
list
(
$relationship
,
$constraints
)
=
array
(
$constraints
,
null
);
}
$this
->
includes
[
$relationship
]
=
$constraints
;
}
//remove duplicates and reset the array keys.
$this
->
includes
=
array_values
(
array_unique
(
$all_includes
));
return
$this
;
}
...
...
laravel/database/eloquent/query.php
View file @
5c3ede74
...
...
@@ -217,22 +217,23 @@ class Query {
*/
protected
function
model_includes
()
{
$includes
=
array
();
$relationships
=
array_keys
(
$this
->
model
->
includes
);
$implicits
=
array
();
foreach
(
$
this
->
model
->
includes
as
$relationship
=>
$constraints
)
foreach
(
$
relationships
as
$relationship
)
{
// When eager loading relationships, constraints may be set on the eager
// load definition; however, is none are set, we need to swap the key
// and the value of the array since there are no constraints.
if
(
is_numeric
(
$relationship
)
)
$parts
=
explode
(
'.'
,
$relationship
);
$prefix
=
''
;
foreach
(
$parts
as
$part
)
{
list
(
$relationship
,
$constraints
)
=
array
(
$constraints
,
null
);
$implicits
[
$prefix
.
$part
]
=
NULL
;
$prefix
.=
$part
.
'.'
;
}
$includes
[
$relationship
]
=
$constraints
;
}
return
$includes
;
// Add all implicit includes to the explicit ones
return
$this
->
model
->
includes
+
$implicits
;
}
/**
...
...
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