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
3e26e05b
Commit
3e26e05b
authored
Feb 16, 2017
by
Jens Segers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix issue with renamed properties for belongsTo and belongsToMany
parent
d9543de4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
20 deletions
+30
-20
HybridRelations.php
src/Jenssegers/Mongodb/Eloquent/HybridRelations.php
+21
-9
BelongsTo.php
src/Jenssegers/Mongodb/Relations/BelongsTo.php
+2
-4
BelongsToMany.php
src/Jenssegers/Mongodb/Relations/BelongsToMany.php
+7
-7
No files found.
src/Jenssegers/Mongodb/Eloquent/HybridRelations.php
View file @
3e26e05b
...
@@ -22,7 +22,7 @@ trait HybridRelations
...
@@ -22,7 +22,7 @@ trait HybridRelations
public
function
hasOne
(
$related
,
$foreignKey
=
null
,
$localKey
=
null
)
public
function
hasOne
(
$related
,
$foreignKey
=
null
,
$localKey
=
null
)
{
{
// Check if it is a relation with an original model.
// Check if it is a relation with an original model.
if
(
!
is_subclass_of
(
$related
,
'Jenssegers\Mongodb\Eloquent\Model'
))
{
if
(
!
is_subclass_of
(
$related
,
\Jenssegers\Mongodb\Eloquent\Model
::
class
))
{
return
parent
::
hasOne
(
$related
,
$foreignKey
,
$localKey
);
return
parent
::
hasOne
(
$related
,
$foreignKey
,
$localKey
);
}
}
...
@@ -48,7 +48,7 @@ trait HybridRelations
...
@@ -48,7 +48,7 @@ trait HybridRelations
public
function
morphOne
(
$related
,
$name
,
$type
=
null
,
$id
=
null
,
$localKey
=
null
)
public
function
morphOne
(
$related
,
$name
,
$type
=
null
,
$id
=
null
,
$localKey
=
null
)
{
{
// Check if it is a relation with an original model.
// Check if it is a relation with an original model.
if
(
!
is_subclass_of
(
$related
,
'Jenssegers\Mongodb\Eloquent\Model'
))
{
if
(
!
is_subclass_of
(
$related
,
\Jenssegers\Mongodb\Eloquent\Model
::
class
))
{
return
parent
::
morphOne
(
$related
,
$name
,
$type
,
$id
,
$localKey
);
return
parent
::
morphOne
(
$related
,
$name
,
$type
,
$id
,
$localKey
);
}
}
...
@@ -56,8 +56,6 @@ trait HybridRelations
...
@@ -56,8 +56,6 @@ trait HybridRelations
list
(
$type
,
$id
)
=
$this
->
getMorphs
(
$name
,
$type
,
$id
);
list
(
$type
,
$id
)
=
$this
->
getMorphs
(
$name
,
$type
,
$id
);
$table
=
$instance
->
getTable
();
$localKey
=
$localKey
?:
$this
->
getKeyName
();
$localKey
=
$localKey
?:
$this
->
getKeyName
();
return
new
MorphOne
(
$instance
->
newQuery
(),
$this
,
$type
,
$id
,
$localKey
);
return
new
MorphOne
(
$instance
->
newQuery
(),
$this
,
$type
,
$id
,
$localKey
);
...
@@ -74,7 +72,7 @@ trait HybridRelations
...
@@ -74,7 +72,7 @@ trait HybridRelations
public
function
hasMany
(
$related
,
$foreignKey
=
null
,
$localKey
=
null
)
public
function
hasMany
(
$related
,
$foreignKey
=
null
,
$localKey
=
null
)
{
{
// Check if it is a relation with an original model.
// Check if it is a relation with an original model.
if
(
!
is_subclass_of
(
$related
,
'Jenssegers\Mongodb\Eloquent\Model'
))
{
if
(
!
is_subclass_of
(
$related
,
\Jenssegers\Mongodb\Eloquent\Model
::
class
))
{
return
parent
::
hasMany
(
$related
,
$foreignKey
,
$localKey
);
return
parent
::
hasMany
(
$related
,
$foreignKey
,
$localKey
);
}
}
...
@@ -100,7 +98,7 @@ trait HybridRelations
...
@@ -100,7 +98,7 @@ trait HybridRelations
public
function
morphMany
(
$related
,
$name
,
$type
=
null
,
$id
=
null
,
$localKey
=
null
)
public
function
morphMany
(
$related
,
$name
,
$type
=
null
,
$id
=
null
,
$localKey
=
null
)
{
{
// Check if it is a relation with an original model.
// Check if it is a relation with an original model.
if
(
!
is_subclass_of
(
$related
,
'Jenssegers\Mongodb\Eloquent\Model'
))
{
if
(
!
is_subclass_of
(
$related
,
\Jenssegers\Mongodb\Eloquent\Model
::
class
))
{
return
parent
::
morphMany
(
$related
,
$name
,
$type
,
$id
,
$localKey
);
return
parent
::
morphMany
(
$related
,
$name
,
$type
,
$id
,
$localKey
);
}
}
...
@@ -139,7 +137,7 @@ trait HybridRelations
...
@@ -139,7 +137,7 @@ trait HybridRelations
}
}
// Check if it is a relation with an original model.
// Check if it is a relation with an original model.
if
(
!
is_subclass_of
(
$related
,
'Jenssegers\Mongodb\Eloquent\Model'
))
{
if
(
!
is_subclass_of
(
$related
,
\Jenssegers\Mongodb\Eloquent\Model
::
class
))
{
return
parent
::
belongsTo
(
$related
,
$foreignKey
,
$otherKey
,
$relation
);
return
parent
::
belongsTo
(
$related
,
$foreignKey
,
$otherKey
,
$relation
);
}
}
...
@@ -222,11 +220,11 @@ trait HybridRelations
...
@@ -222,11 +220,11 @@ trait HybridRelations
// 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.
if
(
is_null
(
$relation
))
{
if
(
is_null
(
$relation
))
{
$relation
=
$this
->
g
etBelongsToManyCaller
();
$relation
=
$this
->
g
uessBelongsToManyRelation
();
}
}
// Check if it is a relation with an original model.
// Check if it is a relation with an original model.
if
(
!
is_subclass_of
(
$related
,
'Jenssegers\Mongodb\Eloquent\Model'
))
{
if
(
!
is_subclass_of
(
$related
,
\Jenssegers\Mongodb\Eloquent\Model
::
class
))
{
return
parent
::
belongsToMany
(
$related
,
$collection
,
$foreignKey
,
$otherKey
,
$relation
);
return
parent
::
belongsToMany
(
$related
,
$collection
,
$foreignKey
,
$otherKey
,
$relation
);
}
}
...
@@ -253,4 +251,18 @@ trait HybridRelations
...
@@ -253,4 +251,18 @@ trait HybridRelations
return
new
BelongsToMany
(
$query
,
$this
,
$collection
,
$foreignKey
,
$otherKey
,
$relation
);
return
new
BelongsToMany
(
$query
,
$this
,
$collection
,
$foreignKey
,
$otherKey
,
$relation
);
}
}
/**
* Get the relationship name of the belongs to many.
*
* @return string
*/
protected
function
guessBelongsToManyRelation
()
{
if
(
method_exists
(
$this
,
'getBelongsToManyCaller'
))
{
return
$this
->
getBelongsToManyCaller
();
}
return
parent
::
guessBelongsToManyRelation
();
}
}
}
src/Jenssegers/Mongodb/Relations/BelongsTo.php
View file @
3e26e05b
...
@@ -29,12 +29,10 @@ class BelongsTo extends \Illuminate\Database\Eloquent\Relations\BelongsTo
...
@@ -29,12 +29,10 @@ class BelongsTo extends \Illuminate\Database\Eloquent\Relations\BelongsTo
}
}
/**
/**
* get the Other/Owner Key name based on different version of Illuminate/Database
* Get the owner key with backwards compatible support.
* see commit https://github.com/illuminate/database/commit/6a35698d72e276f435324b7e29b3cd37ef7d5d9c
* @return string
*/
*/
public
function
getOwnerKey
()
public
function
getOwnerKey
()
{
{
return
property_exists
(
$this
,
"ownerKey"
)
?
$this
->
ownerKey
:
$this
->
otherKey
;
return
property_exists
(
$this
,
'ownerKey'
)
?
$this
->
ownerKey
:
$this
->
otherKey
;
}
}
}
}
src/Jenssegers/Mongodb/Relations/BelongsToMany.php
View file @
3e26e05b
...
@@ -96,7 +96,7 @@ class BelongsToMany extends EloquentBelongsToMany
...
@@ -96,7 +96,7 @@ class BelongsToMany extends EloquentBelongsToMany
// First we need to attach any of the associated models that are not currently
// First we need to attach any of the associated models that are not currently
// in this joining table. We'll spin through the given IDs, checking to see
// in this joining table. We'll spin through the given IDs, checking to see
// if they exist in the array of current ones, and if not we will insert.
// if they exist in the array of current ones, and if not we will insert.
$current
=
$this
->
parent
->
{
$this
->
get
Owner
Key
()}
?:
[];
$current
=
$this
->
parent
->
{
$this
->
get
Related
Key
()}
?:
[];
// See issue #256.
// See issue #256.
if
(
$current
instanceof
Collection
)
{
if
(
$current
instanceof
Collection
)
{
...
@@ -170,7 +170,7 @@ class BelongsToMany extends EloquentBelongsToMany
...
@@ -170,7 +170,7 @@ class BelongsToMany extends EloquentBelongsToMany
}
}
// Attach the new ids to the parent model.
// Attach the new ids to the parent model.
$this
->
parent
->
push
(
$this
->
get
Owner
Key
(),
(
array
)
$id
,
true
);
$this
->
parent
->
push
(
$this
->
get
Related
Key
(),
(
array
)
$id
,
true
);
if
(
$touch
)
{
if
(
$touch
)
{
$this
->
touchIfTouching
();
$this
->
touchIfTouching
();
...
@@ -194,7 +194,7 @@ class BelongsToMany extends EloquentBelongsToMany
...
@@ -194,7 +194,7 @@ class BelongsToMany extends EloquentBelongsToMany
$ids
=
(
array
)
$ids
;
$ids
=
(
array
)
$ids
;
// Detach all ids from the parent model.
// Detach all ids from the parent model.
$this
->
parent
->
pull
(
$this
->
get
Owner
Key
(),
$ids
);
$this
->
parent
->
pull
(
$this
->
get
Related
Key
(),
$ids
);
// Prepare the query to select all related objects.
// Prepare the query to select all related objects.
if
(
count
(
$ids
)
>
0
)
{
if
(
count
(
$ids
)
>
0
)
{
...
@@ -281,12 +281,12 @@ class BelongsToMany extends EloquentBelongsToMany
...
@@ -281,12 +281,12 @@ class BelongsToMany extends EloquentBelongsToMany
}
}
/**
/**
*
get the Other/Owner Key name based on different version of Illuminate/Database
*
Get the related key with backwards compatible support.
*
see commit https://github.com/illuminate/database/commit/6a35698d72e276f435324b7e29b3cd37ef7d5d9c
*
* @return string
* @return string
*/
*/
public
function
get
Owner
Key
()
public
function
get
Related
Key
()
{
{
return
property_exists
(
$this
,
"ownerKey"
)
?
$this
->
owner
Key
:
$this
->
otherKey
;
return
property_exists
(
$this
,
'relatedKey'
)
?
$this
->
related
Key
:
$this
->
otherKey
;
}
}
}
}
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