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
dc92dd26
Commit
dc92dd26
authored
Mar 16, 2012
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding auto detection of intermediate table names.
Signed-off-by:
Taylor Otwell
<
taylorotwell@gmail.com
>
parent
c3d95122
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
2 deletions
+33
-2
model.php
laravel/database/eloquent/model.php
+1
-1
has_many_and_belongs_to.php
...tabase/eloquent/relationships/has_many_and_belongs_to.php
+17
-1
helpers.php
laravel/helpers.php
+15
-0
No files found.
laravel/database/eloquent/model.php
View file @
dc92dd26
...
@@ -264,7 +264,7 @@ abstract class Model {
...
@@ -264,7 +264,7 @@ abstract class Model {
* @param string $other
* @param string $other
* @return Relationship
* @return Relationship
*/
*/
public
function
has_many_and_belongs_to
(
$model
,
$table
,
$foreign
=
null
,
$other
=
null
)
public
function
has_many_and_belongs_to
(
$model
,
$table
=
null
,
$foreign
=
null
,
$other
=
null
)
{
{
return
new
Has_Many_And_Belongs_To
(
$this
,
$model
,
$table
,
$foreign
,
$other
);
return
new
Has_Many_And_Belongs_To
(
$this
,
$model
,
$table
,
$foreign
,
$other
);
}
}
...
...
laravel/database/eloquent/relationships/has_many_and_belongs_to.php
View file @
dc92dd26
...
@@ -39,11 +39,27 @@ class Has_Many_And_Belongs_To extends Relationship {
...
@@ -39,11 +39,27 @@ class Has_Many_And_Belongs_To extends Relationship {
{
{
$this
->
other
=
$other
;
$this
->
other
=
$other
;
$this
->
joining
=
$table
;
$this
->
joining
=
$table
?:
$this
->
joining
(
$model
,
$associated
)
;
parent
::
__construct
(
$model
,
$associated
,
$foreign
);
parent
::
__construct
(
$model
,
$associated
,
$foreign
);
}
}
/**
* Determine the joining table name for the relationship.
*
* By default, the name is the models sorted and concatenated with an underscore.
*
* @return string
*/
protected
function
joining
(
$model
,
$associated
)
{
$models
=
array
(
class_basename
(
$model
),
class_basename
(
$associated
));
sort
(
$models
);
return
strtolower
(
$models
[
0
]
.
'_'
.
$models
[
1
]);
}
/**
/**
* Get the properly hydrated results for the relationship.
* Get the properly hydrated results for the relationship.
*
*
...
...
laravel/helpers.php
View file @
dc92dd26
...
@@ -376,6 +376,21 @@ function root_namespace($class, $separator = '\\')
...
@@ -376,6 +376,21 @@ function root_namespace($class, $separator = '\\')
}
}
}
}
/**
* Get the "class basename" of a class or object.
*
* The basename is considered the name of the class minus all namespaces.
*
* @param object|string $class
* @return string
*/
function
class_basename
(
$class
)
{
if
(
is_object
(
$class
))
$class
=
get_class
(
$class
);
return
basename
(
$class
);
}
/**
/**
* Return the value of the given item.
* Return the value of the given item.
*
*
...
...
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