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
924837f0
Commit
924837f0
authored
Feb 18, 2017
by
Jens Segers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Making progress on fixing relations
parent
3e26e05b
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
100 additions
and
25 deletions
+100
-25
BelongsTo.php
src/Jenssegers/Mongodb/Relations/BelongsTo.php
+10
-0
BelongsToMany.php
src/Jenssegers/Mongodb/Relations/BelongsToMany.php
+35
-0
HasMany.php
src/Jenssegers/Mongodb/Relations/HasMany.php
+21
-11
HasOne.php
src/Jenssegers/Mongodb/Relations/HasOne.php
+33
-13
MorphTo.php
src/Jenssegers/Mongodb/Relations/MorphTo.php
+1
-1
No files found.
src/Jenssegers/Mongodb/Relations/BelongsTo.php
View file @
924837f0
<?php
namespace
Jenssegers\Mongodb\Relations
;
use
Illuminate\Database\Eloquent\Builder
;
class
BelongsTo
extends
\Illuminate\Database\Eloquent\Relations\BelongsTo
{
/**
...
...
@@ -28,6 +30,14 @@ class BelongsTo extends \Illuminate\Database\Eloquent\Relations\BelongsTo
$this
->
query
->
whereIn
(
$key
,
$this
->
getEagerModelKeys
(
$models
));
}
/**
* @inheritdoc
*/
public
function
getRelationExistenceQuery
(
Builder
$query
,
Builder
$parentQuery
,
$columns
=
[
'*'
])
{
return
$query
;
}
/**
* Get the owner key with backwards compatible support.
*/
...
...
src/Jenssegers/Mongodb/Relations/BelongsToMany.php
View file @
924837f0
<?php
namespace
Jenssegers\Mongodb\Relations
;
use
Illuminate\Database\Eloquent\Builder
;
use
Illuminate\Database\Eloquent\Collection
;
use
Illuminate\Database\Eloquent\Model
;
use
Illuminate\Database\Eloquent\Relations\BelongsToMany
as
EloquentBelongsToMany
;
class
BelongsToMany
extends
EloquentBelongsToMany
{
/**
* Get the key for comparing against the parent key in "has" query.
*
* @return string
*/
public
function
getHasCompareKey
()
{
return
$this
->
getForeignKey
();
}
/**
* @inheritdoc
*/
public
function
getRelationExistenceQuery
(
Builder
$query
,
Builder
$parentQuery
,
$columns
=
[
'*'
])
{
return
$query
;
}
/**
* @inheritdoc
*/
...
...
@@ -25,6 +44,14 @@ class BelongsToMany extends EloquentBelongsToMany
return
$columns
;
}
/**
* @inheritdoc
*/
protected
function
shouldSelect
(
array
$columns
=
[
'*'
])
{
return
$columns
;
}
/**
* @inheritdoc
*/
...
...
@@ -260,6 +287,14 @@ class BelongsToMany extends EloquentBelongsToMany
return
$this
->
foreignKey
;
}
/**
* @inheritdoc
*/
public
function
getQualifiedForeignKeyName
()
{
return
$this
->
foreignKey
;
}
/**
* Format the sync list so that it is keyed by ID. (Legacy Support)
* The original function has been renamed to formatRecordsList since Laravel 5.3
...
...
src/Jenssegers/Mongodb/Relations/HasMany.php
View file @
924837f0
...
...
@@ -5,6 +5,26 @@ use Illuminate\Database\Eloquent\Relations\HasMany as EloquentHasMany;
class
HasMany
extends
EloquentHasMany
{
/**
* Get the key for comparing against the parent key in "has" query.
*
* @return string
*/
public
function
getHasCompareKey
()
{
return
$this
->
getForeignKeyName
();
}
/**
* @inheritdoc
*/
public
function
getRelationExistenceQuery
(
Builder
$query
,
Builder
$parentQuery
,
$columns
=
[
'*'
])
{
$foreignKey
=
$this
->
getHasCompareKey
();
return
$query
->
select
(
$foreignKey
)
->
where
(
$foreignKey
,
'exists'
,
true
);
}
/**
* Add the constraints for a relationship count query.
*
...
...
@@ -16,7 +36,7 @@ class HasMany extends EloquentHasMany
{
$foreignKey
=
$this
->
getHasCompareKey
();
return
$query
->
select
(
$
this
->
getHasCompareKey
())
->
where
(
$this
->
getHasCompareKey
()
,
'exists'
,
true
);
return
$query
->
select
(
$
foreignKey
)
->
where
(
$foreignKey
,
'exists'
,
true
);
}
/**
...
...
@@ -35,14 +55,4 @@ class HasMany extends EloquentHasMany
return
$query
->
where
(
$this
->
getHasCompareKey
(),
'exists'
,
true
);
}
/**
* Get the plain foreign key.
*
* @return string
*/
public
function
getPlainForeignKey
()
{
return
$this
->
getForeignKey
();
}
}
src/Jenssegers/Mongodb/Relations/HasOne.php
View file @
924837f0
...
...
@@ -5,6 +5,36 @@ use Illuminate\Database\Eloquent\Relations\HasOne as EloquentHasOne;
class
HasOne
extends
EloquentHasOne
{
/**
* Get the key for comparing against the parent key in "has" query.
*
* @return string
*/
public
function
getForeignKeyName
()
{
return
$this
->
foreignKey
;
}
/**
* Get the key for comparing against the parent key in "has" query.
*
* @return string
*/
public
function
getHasCompareKey
()
{
return
$this
->
getForeignKeyName
();
}
/**
* @inheritdoc
*/
public
function
getRelationExistenceQuery
(
Builder
$query
,
Builder
$parentQuery
,
$columns
=
[
'*'
])
{
$foreignKey
=
$this
->
getForeignKeyName
();
return
$query
->
select
(
$foreignKey
)
->
where
(
$foreignKey
,
'exists'
,
true
);
}
/**
* Add the constraints for a relationship count query.
*
...
...
@@ -14,9 +44,9 @@ class HasOne extends EloquentHasOne
*/
public
function
getRelationCountQuery
(
Builder
$query
,
Builder
$parent
)
{
$foreignKey
=
$this
->
get
HasCompareKey
();
$foreignKey
=
$this
->
get
ForeignKeyName
();
return
$query
->
select
(
$
this
->
getHasCompareKey
())
->
where
(
$this
->
getHasCompareKey
()
,
'exists'
,
true
);
return
$query
->
select
(
$
foreignKey
)
->
where
(
$foreignKey
,
'exists'
,
true
);
}
/**
...
...
@@ -33,16 +63,6 @@ class HasOne extends EloquentHasOne
$key
=
$this
->
wrap
(
$this
->
getQualifiedParentKeyName
());
return
$query
->
where
(
$this
->
getHasCompareKey
(),
'exists'
,
true
);
}
/**
* Get the plain foreign key.
*
* @return string
*/
public
function
getPlainForeignKey
()
{
return
$this
->
getForeignKey
();
return
$query
->
where
(
$this
->
getForeignKeyName
(),
'exists'
,
true
);
}
}
src/Jenssegers/Mongodb/Relations/MorphTo.php
View file @
924837f0
...
...
@@ -28,7 +28,7 @@ class MorphTo extends EloquentMorphTo
$query
=
$instance
->
newQuery
();
return
$query
->
whereIn
(
$key
,
$this
->
gatherKeysByType
(
$type
)
->
all
()
)
->
get
();
return
$query
->
whereIn
(
$key
,
$this
->
gatherKeysByType
(
$type
))
->
get
();
}
/**
...
...
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