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
1c4df65a
Commit
1c4df65a
authored
Jun 16, 2014
by
Jens Segers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Hide interal embedded documents attribute, fixes #229
parent
6df8a487
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
1 deletion
+55
-1
Model.php
src/Jenssegers/Mongodb/Model.php
+17
-1
Builder.php
src/Jenssegers/Mongodb/Query/Builder.php
+25
-0
EmbeddedRelationsTest.php
tests/EmbeddedRelationsTest.php
+10
-0
QueryBuilderTest.php
tests/QueryBuilderTest.php
+3
-0
No files found.
src/Jenssegers/Mongodb/Model.php
View file @
1c4df65a
...
@@ -228,12 +228,28 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
...
@@ -228,12 +228,28 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
// MongoDB related objects to a string representation. This kind
// MongoDB related objects to a string representation. This kind
// of mimics the SQL behaviour so that dates are formatted
// of mimics the SQL behaviour so that dates are formatted
// nicely when your models are converted to JSON.
// nicely when your models are converted to JSON.
foreach
(
$attributes
as
&
$value
)
foreach
(
$attributes
as
$key
=>
&
$value
)
{
{
if
(
$value
instanceof
MongoId
)
if
(
$value
instanceof
MongoId
)
{
{
$value
=
(
string
)
$value
;
$value
=
(
string
)
$value
;
}
}
// If the attribute starts with an underscore, it might be the
// internal array of embedded documents. In that case, we need
// to hide these from the output so that the relation-based
// attribute can take over.
else
if
(
starts_with
(
$key
,
'_'
))
{
$camelKey
=
camel_case
(
$key
);
// If we can find a method that responds to this relation we
// will remove it from the output.
if
(
method_exists
(
$this
,
$camelKey
))
{
unset
(
$attributes
[
$key
]);
}
}
}
}
return
$attributes
;
return
$attributes
;
...
...
src/Jenssegers/Mongodb/Query/Builder.php
View file @
1c4df65a
...
@@ -663,6 +663,31 @@ class Builder extends \Illuminate\Database\Query\Builder {
...
@@ -663,6 +663,31 @@ class Builder extends \Illuminate\Database\Query\Builder {
return
$id
;
return
$id
;
}
}
/**
* Add a basic where clause to the query.
*
* @param string $column
* @param string $operator
* @param mixed $value
* @param string $boolean
* @return \Illuminate\Database\Query\Builder|static
*
* @throws \InvalidArgumentException
*/
public
function
where
(
$column
,
$operator
=
null
,
$value
=
null
,
$boolean
=
'and'
)
{
// Remove the leading $ from operators.
if
(
func_num_args
()
==
3
)
{
if
(
starts_with
(
$operator
,
'$'
))
{
$operator
=
substr
(
$operator
,
1
);
}
}
return
parent
::
where
(
$column
,
$operator
,
$value
,
$boolean
);
}
/**
/**
* Compile the where array.
* Compile the where array.
*
*
...
...
tests/EmbeddedRelationsTest.php
View file @
1c4df65a
...
@@ -82,6 +82,16 @@ class EmbeddedRelationsTest extends TestCase {
...
@@ -82,6 +82,16 @@ class EmbeddedRelationsTest extends TestCase {
$this
->
assertEquals
(
array
(
'London'
,
'Manhattan'
,
'Bruxelles'
),
$freshUser
->
addresses
->
lists
(
'city'
));
$this
->
assertEquals
(
array
(
'London'
,
'Manhattan'
,
'Bruxelles'
),
$freshUser
->
addresses
->
lists
(
'city'
));
}
}
public
function
testEmbedsToArray
()
{
$user
=
User
::
create
(
array
(
'name'
=>
'John Doe'
));
$user
->
addresses
()
->
saveMany
(
array
(
new
Address
(
array
(
'city'
=>
'London'
)),
new
Address
(
array
(
'city'
=>
'Bristol'
))));
$array
=
$user
->
toArray
();
$this
->
assertFalse
(
array_key_exists
(
'_addresses'
,
$array
));
$this
->
assertTrue
(
array_key_exists
(
'addresses'
,
$array
));
}
public
function
testEmbedsManyAssociate
()
public
function
testEmbedsManyAssociate
()
{
{
$user
=
User
::
create
(
array
(
'name'
=>
'John Doe'
));
$user
=
User
::
create
(
array
(
'name'
=>
'John Doe'
));
...
...
tests/QueryBuilderTest.php
View file @
1c4df65a
...
@@ -520,6 +520,9 @@ class QueryBuilderTest extends TestCase {
...
@@ -520,6 +520,9 @@ class QueryBuilderTest extends TestCase {
$results
=
DB
::
collection
(
'items'
)
->
where
(
'tags'
,
'size'
,
2
)
->
get
();
$results
=
DB
::
collection
(
'items'
)
->
where
(
'tags'
,
'size'
,
2
)
->
get
();
$this
->
assertEquals
(
2
,
count
(
$results
));
$this
->
assertEquals
(
2
,
count
(
$results
));
$results
=
DB
::
collection
(
'items'
)
->
where
(
'tags'
,
'$size'
,
2
)
->
get
();
$this
->
assertEquals
(
2
,
count
(
$results
));
$results
=
DB
::
collection
(
'items'
)
->
where
(
'tags'
,
'size'
,
3
)
->
get
();
$results
=
DB
::
collection
(
'items'
)
->
where
(
'tags'
,
'size'
,
3
)
->
get
();
$this
->
assertEquals
(
0
,
count
(
$results
));
$this
->
assertEquals
(
0
,
count
(
$results
));
...
...
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