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
326e3a80
Unverified
Commit
326e3a80
authored
Jan 30, 2020
by
Divine
Committed by
GitHub
Jan 30, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into pr_1746
parents
b18e97b7
9ebcc5ae
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
14 deletions
+17
-14
QueriesRelationships.php
src/Jenssegers/Mongodb/Helpers/QueriesRelationships.php
+17
-14
No files found.
src/Jenssegers/Mongodb/Helpers/QueriesRelationships.php
View file @
326e3a80
...
@@ -8,13 +8,14 @@ use Illuminate\Database\Eloquent\Builder;
...
@@ -8,13 +8,14 @@ use Illuminate\Database\Eloquent\Builder;
use
Illuminate\Database\Eloquent\Relations\BelongsTo
;
use
Illuminate\Database\Eloquent\Relations\BelongsTo
;
use
Illuminate\Database\Eloquent\Relations\BelongsToMany
;
use
Illuminate\Database\Eloquent\Relations\BelongsToMany
;
use
Illuminate\Database\Eloquent\Relations\HasOneOrMany
;
use
Illuminate\Database\Eloquent\Relations\HasOneOrMany
;
use
Illuminate\Database\Eloquent\Relations\Relation
;
use
Jenssegers\Mongodb\Eloquent\Model
;
use
Jenssegers\Mongodb\Eloquent\Model
;
trait
QueriesRelationships
trait
QueriesRelationships
{
{
/**
/**
* Add a relationship count / exists condition to the query.
* Add a relationship count / exists condition to the query.
* @param string $relation
* @param
Relation|
string $relation
* @param string $operator
* @param string $operator
* @param int $count
* @param int $count
* @param string $boolean
* @param string $boolean
...
@@ -23,11 +24,13 @@ trait QueriesRelationships
...
@@ -23,11 +24,13 @@ trait QueriesRelationships
*/
*/
public
function
has
(
$relation
,
$operator
=
'>='
,
$count
=
1
,
$boolean
=
'and'
,
Closure
$callback
=
null
)
public
function
has
(
$relation
,
$operator
=
'>='
,
$count
=
1
,
$boolean
=
'and'
,
Closure
$callback
=
null
)
{
{
if
(
strpos
(
$relation
,
'.'
)
!==
false
)
{
if
(
is_string
(
$relation
))
{
return
$this
->
hasNested
(
$relation
,
$operator
,
$count
,
$boolean
,
$callback
);
if
(
strpos
(
$relation
,
'.'
)
!==
false
)
{
}
return
$this
->
hasNested
(
$relation
,
$operator
,
$count
,
$boolean
,
$callback
);
}
$relation
=
$this
->
getRelationWithoutConstraints
(
$relation
);
$relation
=
$this
->
getRelationWithoutConstraints
(
$relation
);
}
// If this is a hybrid relation then we can not use a normal whereExists() query that relies on a subquery
// If this is a hybrid relation then we can not use a normal whereExists() query that relies on a subquery
// We need to use a `whereIn` query
// We need to use a `whereIn` query
...
@@ -59,17 +62,17 @@ trait QueriesRelationships
...
@@ -59,17 +62,17 @@ trait QueriesRelationships
}
}
/**
/**
* @param $relation
* @param
Relation
$relation
* @return bool
* @return bool
*/
*/
protected
function
isAcrossConnections
(
$relation
)
protected
function
isAcrossConnections
(
Relation
$relation
)
{
{
return
$relation
->
getParent
()
->
getConnectionName
()
!==
$relation
->
getRelated
()
->
getConnectionName
();
return
$relation
->
getParent
()
->
getConnectionName
()
!==
$relation
->
getRelated
()
->
getConnectionName
();
}
}
/**
/**
* Compare across databases
* Compare across databases
* @param $relation
* @param
Relation
$relation
* @param string $operator
* @param string $operator
* @param int $count
* @param int $count
* @param string $boolean
* @param string $boolean
...
@@ -77,7 +80,7 @@ trait QueriesRelationships
...
@@ -77,7 +80,7 @@ trait QueriesRelationships
* @return mixed
* @return mixed
* @throws Exception
* @throws Exception
*/
*/
public
function
addHybridHas
(
$relation
,
$operator
=
'>='
,
$count
=
1
,
$boolean
=
'and'
,
Closure
$callback
=
null
)
public
function
addHybridHas
(
Relation
$relation
,
$operator
=
'>='
,
$count
=
1
,
$boolean
=
'and'
,
Closure
$callback
=
null
)
{
{
$hasQuery
=
$relation
->
getQuery
();
$hasQuery
=
$relation
->
getQuery
();
if
(
$callback
)
{
if
(
$callback
)
{
...
@@ -99,10 +102,10 @@ trait QueriesRelationships
...
@@ -99,10 +102,10 @@ trait QueriesRelationships
}
}
/**
/**
* @param $relation
* @param
Relation
$relation
* @return string
* @return string
*/
*/
protected
function
getHasCompareKey
(
$relation
)
protected
function
getHasCompareKey
(
Relation
$relation
)
{
{
if
(
method_exists
(
$relation
,
'getHasCompareKey'
))
{
if
(
method_exists
(
$relation
,
'getHasCompareKey'
))
{
return
$relation
->
getHasCompareKey
();
return
$relation
->
getHasCompareKey
();
...
@@ -147,14 +150,14 @@ trait QueriesRelationships
...
@@ -147,14 +150,14 @@ trait QueriesRelationships
/**
/**
* Returns key we are constraining this parent model's query with
* Returns key we are constraining this parent model's query with
* @param $relation
* @param
Relation
$relation
* @return string
* @return string
* @throws Exception
* @throws Exception
*/
*/
protected
function
getRelatedConstraintKey
(
$relation
)
protected
function
getRelatedConstraintKey
(
Relation
$relation
)
{
{
if
(
$relation
instanceof
HasOneOrMany
)
{
if
(
$relation
instanceof
HasOneOrMany
)
{
return
$
this
->
model
->
get
KeyName
();
return
$
relation
->
getLocal
KeyName
();
}
}
if
(
$relation
instanceof
BelongsTo
)
{
if
(
$relation
instanceof
BelongsTo
)
{
...
...
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