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
b5f5927f
Commit
b5f5927f
authored
May 02, 2012
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix bug with many-to-many relationships on non-default database connection.
parent
9ed91af1
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
3 deletions
+17
-3
pivot.php
laravel/database/eloquent/pivot.php
+13
-1
has_many_and_belongs_to.php
...tabase/eloquent/relationships/has_many_and_belongs_to.php
+4
-2
No files found.
laravel/database/eloquent/pivot.php
View file @
b5f5927f
...
...
@@ -20,11 +20,13 @@ class Pivot extends Model {
* Create a new pivot table instance.
*
* @param string $table
* @param string $connection
* @return void
*/
public
function
__construct
(
$table
)
public
function
__construct
(
$table
,
$connection
=
null
)
{
$this
->
pivot_table
=
$table
;
$this
->
connection
=
$connection
;
parent
::
__construct
(
array
(),
true
);
}
...
...
@@ -39,4 +41,14 @@ class Pivot extends Model {
return
$this
->
pivot_table
;
}
/**
* Get the connection used by the pivot table.
*
* @return string
*/
public
function
connection
()
{
return
$this
->
connection
;
}
}
\ No newline at end of file
laravel/database/eloquent/relationships/has_many_and_belongs_to.php
View file @
b5f5927f
...
...
@@ -349,7 +349,7 @@ class Has_Many_And_Belongs_To extends Relationship {
// Every model result for a many-to-many relationship needs a Pivot instance
// to represent the pivot table's columns. Sometimes extra columns are on
// the pivot table that may need to be accessed by the developer.
$pivot
=
new
Pivot
(
$this
->
joining
);
$pivot
=
new
Pivot
(
$this
->
joining
,
$this
->
model
->
connection
()
);
// 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
...
...
@@ -400,7 +400,9 @@ class Has_Many_And_Belongs_To extends Relationship {
*/
public
function
pivot
()
{
return
new
Has_Many
(
$this
->
base
,
new
Pivot
(
$this
->
joining
),
$this
->
foreign_key
());
$pivot
=
new
Pivot
(
$this
->
joining
,
$this
->
model
->
connection
());
return
new
Has_Many
(
$this
->
base
,
$pivot
,
$this
->
foreign_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