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
579bc871
Commit
579bc871
authored
Mar 29, 2012
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleaning up code.
parent
144117c0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
7 deletions
+12
-7
query.php
laravel/database/eloquent/query.php
+1
-1
has_many_and_belongs_to.php
...tabase/eloquent/relationships/has_many_and_belongs_to.php
+11
-6
No files found.
laravel/database/eloquent/query.php
View file @
579bc871
...
...
@@ -183,7 +183,7 @@ class Query {
$query
->
table
->
where_nested
(
$constraints
);
}
// Before matching the models, we will initialize the relationship
// Before matching the models, we will initialize the relationship
s
// to either null for single-value relationships or an array for
// the multi-value relationships as their baseline value.
$query
->
initialize
(
$results
,
$relationship
);
...
...
laravel/database/eloquent/relationships/has_many_and_belongs_to.php
View file @
579bc871
...
...
@@ -239,7 +239,7 @@ class Has_Many_And_Belongs_To extends Relationship {
$this
->
with
=
array_merge
(
$this
->
with
,
array
(
$foreign
,
$other
));
// Since pivot tables may have extra information on them that the developer
// needs
,
we allow an extra array of columns to be specified that will be
// needs we allow an extra array of columns to be specified that will be
// fetched from the pivot table and hydrate into the pivot model.
foreach
(
$this
->
with
as
$column
)
{
...
...
@@ -314,9 +314,14 @@ class Has_Many_And_Belongs_To extends Relationship {
{
$foreign
=
$this
->
foreign_key
();
// For each child we'll just get the parent that connects to the child and set the
// child model on the relationship array using the keys. Once we're done looping
// through the children all of the proper relations will be set.
foreach
(
$children
as
$key
=>
$child
)
{
$parents
[
$child
->
pivot
->
$foreign
]
->
relationships
[
$relationship
][
$child
->
{
$child
->
key
()}]
=
$child
;
$parent
=&
$parents
[
$child
->
pivot
->
$foreign
];
$parent
->
relationships
[
$relationship
][
$child
->
{
$child
->
key
()}]
=
$child
;
}
}
...
...
@@ -337,7 +342,7 @@ class Has_Many_And_Belongs_To extends Relationship {
// If the attribute key starts with "pivot_", we know this is a column on
// the pivot table, so we will move it to the Pivot model and purge it
// from the model since it actually belongs to the pivot.
// from the model since it actually belongs to the pivot
model
.
foreach
(
$result
->
attributes
as
$key
=>
$value
)
{
if
(
starts_with
(
$key
,
'pivot_'
))
...
...
@@ -367,9 +372,9 @@ class Has_Many_And_Belongs_To extends Relationship {
{
$columns
=
(
is_array
(
$columns
))
?
$columns
:
func_get_args
();
// The "with" array contains a couple of columns by default, so we will
//
just merge in the developer specified columns here, and we'll mak
e
//
sure the values of the array are unique
.
// The "with" array contains a couple of columns by default, so we will
just
//
merge in the developer specified columns here, and we will make sur
e
//
the values of the array are unique to avoid duplicates
.
$this
->
with
=
array_unique
(
array_merge
(
$this
->
with
,
$columns
));
$this
->
set_select
(
$this
->
foreign_key
(),
$this
->
other_key
());
...
...
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