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
9cee4693
Commit
9cee4693
authored
Jun 14, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added support for overriding many-to-many table names.
parent
ae711416
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
7 deletions
+17
-7
eloquent.php
system/db/eloquent.php
+3
-2
relate.php
system/db/eloquent/relate.php
+14
-5
No files found.
system/db/eloquent.php
View file @
9cee4693
...
@@ -164,11 +164,12 @@ abstract class Eloquent {
...
@@ -164,11 +164,12 @@ abstract class Eloquent {
* Retrieve the query for a *:* relationship.
* Retrieve the query for a *:* relationship.
*
*
* @param string $model
* @param string $model
* @param string $table
* @return mixed
* @return mixed
*/
*/
public
function
has_many_and_belongs_to
(
$model
)
public
function
has_many_and_belongs_to
(
$model
,
$table
=
null
)
{
{
return
Eloquent\Relate
::
has_many_and_belongs_to
(
$model
,
$this
);
return
Eloquent\Relate
::
has_many_and_belongs_to
(
$model
,
$t
able
,
$t
his
);
}
}
/**
/**
...
...
system/db/eloquent/relate.php
View file @
9cee4693
...
@@ -64,18 +64,27 @@ class Relate {
...
@@ -64,18 +64,27 @@ class Relate {
* Retrieve the query for a *:* relationship.
* Retrieve the query for a *:* relationship.
*
*
* @param string $model
* @param string $model
* @param string $table
* @param object $eloquent
* @param object $eloquent
* @return mixed
* @return mixed
*/
*/
public
static
function
has_many_and_belongs_to
(
$model
,
$eloquent
)
public
static
function
has_many_and_belongs_to
(
$model
,
$
table
,
$
eloquent
)
{
{
// -----------------------------------------------------
// -----------------------------------------------------
//
Get the models involved in the relationship
.
//
Figure out the intermediate table name
.
// -----------------------------------------------------
// -----------------------------------------------------
$models
=
array
(
\System\Str
::
lower
(
$model
),
\System\Str
::
lower
(
get_class
(
$eloquent
)));
if
(
is_null
(
$table
))
sort
(
$models
);
{
$models
=
array
(
\System\Str
::
lower
(
$model
),
\System\Str
::
lower
(
get_class
(
$eloquent
)));
sort
(
$models
);
$eloquent
->
relating_table
=
implode
(
'_'
,
$models
);
}
else
{
$eloquent
->
relating_table
=
$table
;
}
$eloquent
->
relating_table
=
implode
(
'_'
,
$models
);
$eloquent
->
relating
=
__FUNCTION__
;
$eloquent
->
relating
=
__FUNCTION__
;
$eloquent
->
relating_key
=
$eloquent
->
relating_table
.
'.'
.
\System\Str
::
lower
(
get_class
(
$eloquent
))
.
'_id'
;
$eloquent
->
relating_key
=
$eloquent
->
relating_table
.
'.'
.
\System\Str
::
lower
(
get_class
(
$eloquent
))
.
'_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