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
8304a46f
Commit
8304a46f
authored
Mar 29, 2015
by
Jens Segers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Small tweaks
parent
593b4a52
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
35 deletions
+33
-35
BelongsToMany.php
src/Jenssegers/Mongodb/Relations/BelongsToMany.php
+33
-24
MorphTo.php
src/Jenssegers/Mongodb/Relations/MorphTo.php
+0
-11
No files found.
src/Jenssegers/Mongodb/Relations/BelongsToMany.php
View file @
8304a46f
...
@@ -14,12 +14,13 @@ class BelongsToMany extends EloquentBelongsToMany {
...
@@ -14,12 +14,13 @@ class BelongsToMany extends EloquentBelongsToMany {
*/
*/
protected
function
hydratePivotRelation
(
array
$models
)
protected
function
hydratePivotRelation
(
array
$models
)
{
{
// Do nothing
// Do nothing
.
}
}
/**
/**
* Set the select clause for the relation query.
* Set the select clause for the relation query.
*
*
* @param array $columns
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
*/
protected
function
getSelectColumns
(
array
$columns
=
array
(
'*'
))
protected
function
getSelectColumns
(
array
$columns
=
array
(
'*'
))
...
@@ -34,10 +35,21 @@ class BelongsToMany extends EloquentBelongsToMany {
...
@@ -34,10 +35,21 @@ class BelongsToMany extends EloquentBelongsToMany {
*/
*/
public
function
addConstraints
()
public
function
addConstraints
()
{
{
if
(
static
::
$constraints
)
if
(
static
::
$constraints
)
$this
->
setWhere
();
{
}
$this
->
query
->
where
(
$this
->
getForeignKey
(),
'='
,
$this
->
parent
->
getKey
());
}
/**
* Set the where clause for the relation query.
*
* @return $this
*/
protected
function
setWhere
()
{
$foreign
=
$this
->
getForeignKey
();
$this
->
query
->
where
(
$foreign
,
'='
,
$this
->
parent
->
getKey
());
return
$this
;
}
}
/**
/**
...
@@ -82,7 +94,7 @@ class BelongsToMany extends EloquentBelongsToMany {
...
@@ -82,7 +94,7 @@ class BelongsToMany extends EloquentBelongsToMany {
/**
/**
* Sync the intermediate tables with a list of IDs or collection of models.
* Sync the intermediate tables with a list of IDs or collection of models.
*
*
* @param
mixed
$ids
* @param
array
$ids
* @param bool $detaching
* @param bool $detaching
* @return array
* @return array
*/
*/
...
@@ -104,7 +116,11 @@ class BelongsToMany extends EloquentBelongsToMany {
...
@@ -104,7 +116,11 @@ class BelongsToMany extends EloquentBelongsToMany {
$records
=
$this
->
formatSyncList
(
$ids
);
$records
=
$this
->
formatSyncList
(
$ids
);
$detach
=
array_values
(
array_diff
(
$current
,
array_keys
(
$records
)));
$detach
=
array_diff
(
$current
,
array_keys
(
$records
));
// We need to make sure we pass a clean array, so that it is not interpreted
// as an associative array.
$detach
=
array_values
(
$detach
);
// Next, we will take the differences of the currents and given IDs and detach
// Next, we will take the differences of the currents and given IDs and detach
// all of the entities that exist in the "current" array but are not in the
// all of the entities that exist in the "current" array but are not in the
...
@@ -113,7 +129,7 @@ class BelongsToMany extends EloquentBelongsToMany {
...
@@ -113,7 +129,7 @@ class BelongsToMany extends EloquentBelongsToMany {
{
{
$this
->
detach
(
$detach
);
$this
->
detach
(
$detach
);
$changes
[
'detached'
]
=
(
array
)
array_map
(
'intval'
,
$detach
);
$changes
[
'detached'
]
=
(
array
)
array_map
(
function
(
$v
)
{
return
(
int
)
$v
;
}
,
$detach
);
}
}
// Now we are finally ready to attach the new records. Note that we'll disable
// Now we are finally ready to attach the new records. Note that we'll disable
...
@@ -156,33 +172,26 @@ class BelongsToMany extends EloquentBelongsToMany {
...
@@ -156,33 +172,26 @@ class BelongsToMany extends EloquentBelongsToMany {
{
{
if
(
$id
instanceof
Model
)
if
(
$id
instanceof
Model
)
{
{
$model
=
$id
;
$id
=
$model
->
getKey
();
$model
=
$id
;
}
$ids
=
(
array
)
$id
;
$id
=
$model
->
getKey
()
;
// Attach the new ids to the parent model.
// Attach the new parent id to the related model.
$this
->
parent
->
push
(
$this
->
otherKey
,
$ids
,
true
);
// If we have a model instance, we can push the ids to that model,
// so that the internal attributes are updated as well. Otherwise,
// we will just perform a regular database query.
if
(
isset
(
$model
))
{
// Attach the new ids to the related model.
$model
->
push
(
$this
->
foreignKey
,
$this
->
parent
->
getKey
(),
true
);
$model
->
push
(
$this
->
foreignKey
,
$this
->
parent
->
getKey
(),
true
);
}
}
else
else
{
{
$query
=
$this
->
newRelatedQuery
();
$query
=
$this
->
newRelatedQuery
();
// Select related models.
$query
->
whereIn
(
$this
->
related
->
getKeyName
(),
(
array
)
$id
);
$query
->
whereIn
(
$this
->
related
->
getKeyName
(),
$ids
);
// Attach the new parent id to the related model.
// Attach the new parent id to the related model.
$query
->
push
(
$this
->
foreignKey
,
$this
->
parent
->
getKey
(),
true
);
$query
->
push
(
$this
->
foreignKey
,
$this
->
parent
->
getKey
(),
true
);
}
}
// Attach the new ids to the parent model.
$this
->
parent
->
push
(
$this
->
otherKey
,
(
array
)
$id
,
true
);
if
(
$touch
)
$this
->
touchIfTouching
();
if
(
$touch
)
$this
->
touchIfTouching
();
}
}
...
@@ -238,9 +247,9 @@ class BelongsToMany extends EloquentBelongsToMany {
...
@@ -238,9 +247,9 @@ class BelongsToMany extends EloquentBelongsToMany {
foreach
(
$results
as
$result
)
foreach
(
$results
as
$result
)
{
{
foreach
(
$result
->
$foreign
as
$
single
)
foreach
(
$result
->
$foreign
as
$
item
)
{
{
$dictionary
[
$
single
][]
=
$result
;
$dictionary
[
$
item
][]
=
$result
;
}
}
}
}
...
...
src/Jenssegers/Mongodb/Relations/MorphTo.php
View file @
8304a46f
...
@@ -21,15 +21,4 @@ class MorphTo extends EloquentMorphTo {
...
@@ -21,15 +21,4 @@ class MorphTo extends EloquentMorphTo {
}
}
}
}
/**
* Set the constraints for an eager load of the relation.
*
* @param array $models
* @return void
*/
public
function
addEagerConstraints
(
array
$models
)
{
$this
->
buildDictionary
(
$this
->
models
=
Collection
::
make
(
$models
));
}
}
}
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