Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
laravel-mongodb
Project
Project
Details
Activity
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
sinan
laravel-mongodb
Commits
bf38285e
Commit
bf38285e
authored
May 03, 2014
by
Jens Segers
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #202 from Gabrola/belongsto_relation_fix
Fix belongsTo and belongToMany relations
parents
4ffc9be9
3c248001
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
12 deletions
+12
-12
Model.php
src/Jenssegers/Eloquent/Model.php
+12
-12
No files found.
src/Jenssegers/Eloquent/Model.php
View file @
bf38285e
...
@@ -134,12 +134,6 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model {
...
@@ -134,12 +134,6 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model {
*/
*/
public
function
belongsTo
(
$related
,
$foreignKey
=
null
,
$otherKey
=
null
,
$relation
=
null
)
public
function
belongsTo
(
$related
,
$foreignKey
=
null
,
$otherKey
=
null
,
$relation
=
null
)
{
{
// Check if it is a relation with an original model.
if
(
!
is_subclass_of
(
$related
,
'Jenssegers\Mongodb\Model'
))
{
return
parent
::
belongsTo
(
$related
,
$foreignKey
,
$otherKey
,
$relation
);
}
// If no relation name was given, we will use this debug backtrace to extract
// If no relation name was given, we will use this debug backtrace to extract
// the calling method's name and use that as the relationship name as most
// the calling method's name and use that as the relationship name as most
// of the time this will be what we desire to use for the relatinoships.
// of the time this will be what we desire to use for the relatinoships.
...
@@ -150,6 +144,12 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model {
...
@@ -150,6 +144,12 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model {
$relation
=
$caller
[
'function'
];
$relation
=
$caller
[
'function'
];
}
}
// Check if it is a relation with an original model.
if
(
!
is_subclass_of
(
$related
,
'Jenssegers\Mongodb\Model'
))
{
return
parent
::
belongsTo
(
$related
,
$foreignKey
,
$otherKey
,
$relation
);
}
// If no foreign key was supplied, we can use a backtrace to guess the proper
// If no foreign key was supplied, we can use a backtrace to guess the proper
// foreign key name by using the name of the relationship function, which
// foreign key name by using the name of the relationship function, which
// when combined with an "_id" should conventionally match the columns.
// when combined with an "_id" should conventionally match the columns.
...
@@ -227,12 +227,6 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model {
...
@@ -227,12 +227,6 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model {
*/
*/
public
function
belongsToMany
(
$related
,
$collection
=
null
,
$foreignKey
=
null
,
$otherKey
=
null
,
$relation
=
null
)
public
function
belongsToMany
(
$related
,
$collection
=
null
,
$foreignKey
=
null
,
$otherKey
=
null
,
$relation
=
null
)
{
{
// Check if it is a relation with an original model.
if
(
!
is_subclass_of
(
$related
,
'Jenssegers\Mongodb\Model'
))
{
return
parent
::
belongsToMany
(
$related
,
$collection
,
$foreignKey
,
$otherKey
,
$relation
);
}
// If no relationship name was passed, we will pull backtraces to get the
// If no relationship name was passed, we will pull backtraces to get the
// name of the calling function. We will use that function name as the
// name of the calling function. We will use that function name as the
// title of this relation since that is a great convention to apply.
// title of this relation since that is a great convention to apply.
...
@@ -241,6 +235,12 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model {
...
@@ -241,6 +235,12 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model {
$relation
=
$this
->
getBelongsToManyCaller
();
$relation
=
$this
->
getBelongsToManyCaller
();
}
}
// Check if it is a relation with an original model.
if
(
!
is_subclass_of
(
$related
,
'Jenssegers\Mongodb\Model'
))
{
return
parent
::
belongsToMany
(
$related
,
$collection
,
$foreignKey
,
$otherKey
,
$relation
);
}
// First, we'll need to determine the foreign key and "other key" for the
// First, we'll need to determine the foreign key and "other key" for the
// relationship. Once we have determined the keys we'll make the query
// relationship. Once we have determined the keys we'll make the query
// instances as well as the relationship instances we need for this.
// instances as well as the relationship instances we need for this.
...
...
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