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
17cc5037
Commit
17cc5037
authored
Jul 20, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support for self-referential many-to-many relationships in Eloquent.
parent
b4c7dcb9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
3 deletions
+7
-3
eloquent.php
system/db/eloquent.php
+7
-3
No files found.
system/db/eloquent.php
View file @
17cc5037
...
@@ -264,9 +264,11 @@ abstract class Eloquent {
...
@@ -264,9 +264,11 @@ abstract class Eloquent {
*
*
* @param string $model
* @param string $model
* @param string $table
* @param string $table
* @param string $foreign_key
* @param string $associated_key
* @return mixed
* @return mixed
*/
*/
public
function
has_and_belongs_to_many
(
$model
,
$table
=
null
)
public
function
has_and_belongs_to_many
(
$model
,
$table
=
null
,
$foreign_key
=
null
,
$associated_key
=
null
)
{
{
$this
->
relating
=
__FUNCTION__
;
$this
->
relating
=
__FUNCTION__
;
...
@@ -283,11 +285,13 @@ abstract class Eloquent {
...
@@ -283,11 +285,13 @@ abstract class Eloquent {
$this
->
relating_table
=
$table
;
$this
->
relating_table
=
$table
;
}
}
$this
->
relating_key
=
strtolower
(
get_class
(
$this
))
.
'_id'
;
$this
->
relating_key
=
(
is_null
(
$foreign_key
))
?
strtolower
(
get_class
(
$this
))
.
'_id'
:
$foreign_key
;
$associated_key
=
(
is_null
(
$associated_key
))
?
strtolower
(
$model
)
.
'_id'
:
$associated_key
;
return
static
::
make
(
$model
)
return
static
::
make
(
$model
)
->
select
(
array
(
static
::
table
(
$model
)
.
'.*'
))
->
select
(
array
(
static
::
table
(
$model
)
.
'.*'
))
->
join
(
$this
->
relating_table
,
static
::
table
(
$model
)
.
'.id'
,
'='
,
$this
->
relating_table
.
'.'
.
strtolower
(
$model
)
.
'_id'
)
->
join
(
$this
->
relating_table
,
static
::
table
(
$model
)
.
'.id'
,
'='
,
$this
->
relating_table
.
'.'
.
$associated_key
)
->
where
(
$this
->
relating_table
.
'.'
.
$this
->
relating_key
,
'='
,
$this
->
id
);
->
where
(
$this
->
relating_table
.
'.'
.
$this
->
relating_key
,
'='
,
$this
->
id
);
}
}
...
...
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