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
37fd54b8
Commit
37fd54b8
authored
Mar 26, 2012
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #448 from danielboendergaard/patch-1
Fixed problem with Eloquent2 pivot tables
parents
158bc32c
3639d2c4
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
8 deletions
+6
-8
has_many_and_belongs_to.php
...tabase/eloquent/relationships/has_many_and_belongs_to.php
+6
-8
No files found.
laravel/database/eloquent/relationships/has_many_and_belongs_to.php
View file @
37fd54b8
...
@@ -290,20 +290,18 @@ class Has_Many_And_Belongs_To extends Relationship {
...
@@ -290,20 +290,18 @@ class Has_Many_And_Belongs_To extends Relationship {
// the pivot table that may need to be accessed by the developer.
// the pivot table that may need to be accessed by the developer.
$pivot
=
new
Pivot
(
$this
->
joining
);
$pivot
=
new
Pivot
(
$this
->
joining
);
$attributes
=
array_filter
(
$result
->
attributes
,
function
(
$attribute
)
{
return
starts_with
(
$attribute
,
'pivot_'
);
});
// If the attribute key starts with "pivot_", we know this is a column on
// 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
// 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.
foreach
(
$attributes
as
$key
=>
$value
)
foreach
(
$result
->
attributes
as
$key
=>
$value
)
{
if
(
starts_with
(
$key
,
'pivot_'
))
{
{
$pivot
->
{
substr
(
$key
,
6
)}
=
$value
;
$pivot
->
{
substr
(
$key
,
6
)}
=
$value
;
$result
->
purge
(
$key
);
$result
->
purge
(
$key
);
}
}
}
// Once we have completed hydrating the pivot model instance, we'll set
// Once we have completed hydrating the pivot model instance, we'll set
// it on the result model's relationships array so the developer can
// it on the result model's relationships array so the developer can
...
...
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