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
5e0e2882
Commit
5e0e2882
authored
Aug 08, 2014
by
Jens Segers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Small tweaks
parent
357f65f5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
16 deletions
+36
-16
Builder.php
src/Jenssegers/Mongodb/Query/Builder.php
+18
-13
EmbedsOneOrMany.php
src/Jenssegers/Mongodb/Relations/EmbedsOneOrMany.php
+16
-0
EmbeddedRelationsTest.php
tests/EmbeddedRelationsTest.php
+2
-3
No files found.
src/Jenssegers/Mongodb/Query/Builder.php
View file @
5e0e2882
...
@@ -363,7 +363,13 @@ class Builder extends \Illuminate\Database\Query\Builder {
...
@@ -363,7 +363,13 @@ class Builder extends \Illuminate\Database\Query\Builder {
*/
*/
public
function
update
(
array
$values
,
array
$options
=
array
())
public
function
update
(
array
$values
,
array
$options
=
array
())
{
{
return
$this
->
performUpdate
(
array
(
'$set'
=>
$values
),
$options
);
// Use $set as default operator.
if
(
!
starts_with
(
key
(
$values
),
'$'
))
{
$values
=
array
(
'$set'
=>
$values
);
}
return
$this
->
performUpdate
(
$values
,
$options
);
}
}
/**
/**
...
@@ -376,11 +382,9 @@ class Builder extends \Illuminate\Database\Query\Builder {
...
@@ -376,11 +382,9 @@ class Builder extends \Illuminate\Database\Query\Builder {
*/
*/
public
function
increment
(
$column
,
$amount
=
1
,
array
$extra
=
array
(),
array
$options
=
array
())
public
function
increment
(
$column
,
$amount
=
1
,
array
$extra
=
array
(),
array
$options
=
array
())
{
{
$query
=
array
(
$query
=
array
(
'$inc'
=>
array
(
$column
=>
$amount
));
'$inc'
=>
array
(
$column
=>
$amount
)
);
if
(
!
empty
(
$extra
))
if
(
!
empty
(
$extra
))
{
{
$query
[
'$set'
]
=
$extra
;
$query
[
'$set'
]
=
$extra
;
}
}
...
@@ -490,7 +494,7 @@ class Builder extends \Illuminate\Database\Query\Builder {
...
@@ -490,7 +494,7 @@ class Builder extends \Illuminate\Database\Query\Builder {
}
}
// Create an expression for the given value
// Create an expression for the given value
else
if
(
!
is_null
(
$expression
))
else
if
(
!
is_null
(
$expression
))
{
{
return
new
Expression
(
$expression
);
return
new
Expression
(
$expression
);
}
}
...
@@ -552,7 +556,7 @@ class Builder extends \Illuminate\Database\Query\Builder {
...
@@ -552,7 +556,7 @@ class Builder extends \Illuminate\Database\Query\Builder {
*/
*/
public
function
drop
(
$columns
)
public
function
drop
(
$columns
)
{
{
if
(
!
is_array
(
$columns
))
$columns
=
array
(
$columns
);
if
(
!
is_array
(
$columns
))
$columns
=
array
(
$columns
);
$fields
=
array
();
$fields
=
array
();
...
@@ -585,13 +589,14 @@ class Builder extends \Illuminate\Database\Query\Builder {
...
@@ -585,13 +589,14 @@ class Builder extends \Illuminate\Database\Query\Builder {
*/
*/
protected
function
performUpdate
(
$query
,
array
$options
=
array
())
protected
function
performUpdate
(
$query
,
array
$options
=
array
())
{
{
//
Default options
//
Update multiple items by default.
$default
=
array
(
'multiple'
=>
true
);
if
(
!
array_key_exists
(
'multiple'
,
$options
))
{
// Merge options and override default options
$options
[
'multiple'
]
=
true
;
$options
=
array_merge
(
$default
,
$options
);
}
$wheres
=
$this
->
compileWheres
();
$wheres
=
$this
->
compileWheres
();
$result
=
$this
->
collection
->
update
(
$wheres
,
$query
,
$options
);
$result
=
$this
->
collection
->
update
(
$wheres
,
$query
,
$options
);
if
(
1
==
(
int
)
$result
[
'ok'
])
if
(
1
==
(
int
)
$result
[
'ok'
])
...
@@ -682,7 +687,7 @@ class Builder extends \Illuminate\Database\Query\Builder {
...
@@ -682,7 +687,7 @@ class Builder extends \Illuminate\Database\Query\Builder {
}
}
// Convert id's.
// Convert id's.
if
(
isset
(
$where
[
'column'
])
and
$where
[
'column'
]
==
'_id'
)
if
(
isset
(
$where
[
'column'
])
and
(
$where
[
'column'
]
==
'_id'
or
ends_with
(
$where
[
'column'
],
'._id'
))
)
{
{
// Multiple values.
// Multiple values.
if
(
isset
(
$where
[
'values'
]))
if
(
isset
(
$where
[
'values'
]))
...
...
src/Jenssegers/Mongodb/Relations/EmbedsOneOrMany.php
View file @
5e0e2882
...
@@ -48,6 +48,12 @@ abstract class EmbedsOneOrMany extends Relation {
...
@@ -48,6 +48,12 @@ abstract class EmbedsOneOrMany extends Relation {
$this
->
foreignKey
=
$foreignKey
;
$this
->
foreignKey
=
$foreignKey
;
$this
->
relation
=
$relation
;
$this
->
relation
=
$relation
;
// If this is a nested relation, we need to get the parent query instead.
if
(
$parentRelation
=
$this
->
getParentRelation
())
{
$this
->
query
=
$parentRelation
->
getQuery
();
}
$this
->
addConstraints
();
$this
->
addConstraints
();
}
}
...
@@ -312,4 +318,14 @@ abstract class EmbedsOneOrMany extends Relation {
...
@@ -312,4 +318,14 @@ abstract class EmbedsOneOrMany extends Relation {
return
$model
;
return
$model
;
}
}
/**
* Get the relation instance of the parent.
*
* @return Illuminate\Database\Eloquent\Relations\Relation
*/
protected
function
getParentRelation
()
{
return
$this
->
parent
->
getParent
();
}
}
}
tests/EmbeddedRelationsTest.php
View file @
5e0e2882
...
@@ -179,7 +179,7 @@ class EmbeddedRelationsTest extends TestCase {
...
@@ -179,7 +179,7 @@ class EmbeddedRelationsTest extends TestCase {
$this
->
assertEquals
(
array
(
'Bruxelles'
,
'Paris'
),
$freshUser
->
addresses
->
lists
(
'city'
));
$this
->
assertEquals
(
array
(
'Bruxelles'
,
'Paris'
),
$freshUser
->
addresses
->
lists
(
'city'
));
}
}
/*
public function testEmbedsManyDestroy()
public
function
testEmbedsManyDestroy
()
{
{
$user
=
User
::
create
(
array
(
'name'
=>
'John Doe'
));
$user
=
User
::
create
(
array
(
'name'
=>
'John Doe'
));
$user
->
addresses
()
->
saveMany
(
array
(
new
Address
(
array
(
'city'
=>
'London'
)),
new
Address
(
array
(
'city'
=>
'Bristol'
)),
new
Address
(
array
(
'city'
=>
'Bruxelles'
))));
$user
->
addresses
()
->
saveMany
(
array
(
new
Address
(
array
(
'city'
=>
'London'
)),
new
Address
(
array
(
'city'
=>
'Bristol'
)),
new
Address
(
array
(
'city'
=>
'Bruxelles'
))));
...
@@ -215,7 +215,7 @@ class EmbeddedRelationsTest extends TestCase {
...
@@ -215,7 +215,7 @@ class EmbeddedRelationsTest extends TestCase {
list
(
$london
,
$bristol
,
$bruxelles
)
=
$user
->
addresses
()
->
saveMany
(
array
(
new
Address
(
array
(
'city'
=>
'London'
)),
new
Address
(
array
(
'city'
=>
'Bristol'
)),
new
Address
(
array
(
'city'
=>
'Bruxelles'
))));
list
(
$london
,
$bristol
,
$bruxelles
)
=
$user
->
addresses
()
->
saveMany
(
array
(
new
Address
(
array
(
'city'
=>
'London'
)),
new
Address
(
array
(
'city'
=>
'Bristol'
)),
new
Address
(
array
(
'city'
=>
'Bruxelles'
))));
$user
->
addresses
()
->
destroy
(
array
(
$london
,
$bruxelles
));
$user
->
addresses
()
->
destroy
(
array
(
$london
,
$bruxelles
));
$this
->
assertEquals
(
array
(
'Bristol'
),
$user
->
addresses
->
lists
(
'city'
));
$this
->
assertEquals
(
array
(
'Bristol'
),
$user
->
addresses
->
lists
(
'city'
));
}
*/
}
public
function
testEmbedsManyDissociate
()
public
function
testEmbedsManyDissociate
()
{
{
...
@@ -498,7 +498,6 @@ class EmbeddedRelationsTest extends TestCase {
...
@@ -498,7 +498,6 @@ class EmbeddedRelationsTest extends TestCase {
$user
=
User
::
where
(
'name'
,
'John Doe'
)
->
first
();
$user
=
User
::
where
(
'name'
,
'John Doe'
)
->
first
();
$this
->
assertEquals
(
'Ghent'
,
$user
->
addresses
->
first
()
->
city
);
$this
->
assertEquals
(
'Ghent'
,
$user
->
addresses
->
first
()
->
city
);
$this
->
assertEquals
(
'Mark Doe'
,
$user
->
father
->
name
);
$this
->
assertEquals
(
'Mark Doe'
,
$user
->
father
->
name
);
}
}
}
}
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