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
722668de
Commit
722668de
authored
Dec 03, 2015
by
Jens Segers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Apply some Laravel changes
parent
64c46697
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
30 additions
and
25 deletions
+30
-25
composer.json
composer.json
+1
-2
HybridRelations.php
src/Jenssegers/Mongodb/Eloquent/HybridRelations.php
+10
-7
Builder.php
src/Jenssegers/Mongodb/Query/Builder.php
+15
-13
MorphTo.php
src/Jenssegers/Mongodb/Relations/MorphTo.php
+1
-0
QueryBuilderTest.php
tests/QueryBuilderTest.php
+1
-1
RelationsTest.php
tests/RelationsTest.php
+2
-2
No files found.
composer.json
View file @
722668de
...
...
@@ -38,6 +38,5 @@
"suggest"
:
{
"jenssegers/mongodb-session"
:
"Add MongoDB session support to Laravel-MongoDB"
,
"jenssegers/mongodb-sentry"
:
"Add Sentry support to Laravel-MongoDB"
},
"minimum-stability"
:
"dev"
}
}
src/Jenssegers/Mongodb/Eloquent/HybridRelations.php
View file @
722668de
...
...
@@ -2,6 +2,7 @@
use
Illuminate\Database\Eloquent\Relations\MorphMany
;
use
Illuminate\Database\Eloquent\Relations\MorphOne
;
use
Illuminate\Support\Str
;
use
Jenssegers\Mongodb\Model
;
use
Jenssegers\Mongodb\Relations\BelongsTo
;
use
Jenssegers\Mongodb\Relations\BelongsToMany
;
...
...
@@ -135,10 +136,10 @@ trait HybridRelations {
{
// If no relation name was given, we will use this debug backtrace to extract
// the calling method's name and use that as the relationship name as most
// of the time this will be what we desire to use for the relati
no
ships.
// of the time this will be what we desire to use for the relati
on
ships.
if
(
is_null
(
$relation
))
{
list
(
,
$caller
)
=
debug_backtrace
(
false
);
list
(
$current
,
$caller
)
=
debug_backtrace
(
false
,
2
);
$relation
=
$caller
[
'function'
];
}
...
...
@@ -154,7 +155,7 @@ trait HybridRelations {
// when combined with an "_id" should conventionally match the columns.
if
(
is_null
(
$foreignKey
))
{
$foreignKey
=
snake_cas
e
(
$relation
)
.
'_id'
;
$foreignKey
=
Str
::
snak
e
(
$relation
)
.
'_id'
;
}
$instance
=
new
$related
;
...
...
@@ -184,9 +185,9 @@ trait HybridRelations {
// use that to get both the class and foreign key that will be utilized.
if
(
is_null
(
$name
))
{
list
(
,
$caller
)
=
debug_backtrace
(
false
);
list
(
$current
,
$caller
)
=
debug_backtrace
(
false
,
2
);
$name
=
snake_cas
e
(
$caller
[
'function'
]);
$name
=
Str
::
snak
e
(
$caller
[
'function'
]);
}
list
(
$type
,
$id
)
=
$this
->
getMorphs
(
$name
,
$type
,
$id
);
...
...
@@ -201,15 +202,17 @@ trait HybridRelations {
);
}
// If we are not eager loading the relati
nship,
we will essentially treat this
// If we are not eager loading the relati
onship
we will essentially treat this
// as a belongs-to style relationship since morph-to extends that class and
// we will pass in the appropriate values so that it behaves as expected.
else
{
$class
=
$this
->
getActualClassNameForMorph
(
$class
);
$instance
=
new
$class
;
return
new
MorphTo
(
with
(
$instance
)
->
newQuery
(),
$this
,
$id
,
$instance
->
getKeyName
(),
$type
,
$name
$instance
->
newQuery
(),
$this
,
$id
,
$instance
->
getKeyName
(),
$type
,
$name
);
}
}
...
...
src/Jenssegers/Mongodb/Query/Builder.php
View file @
722668de
...
...
@@ -4,6 +4,7 @@ use Closure;
use
DateTime
;
use
Illuminate\Database\Query\Builder
as
BaseBuilder
;
use
Illuminate\Database\Query\Expression
;
use
Illuminate\Support\Arr
;
use
Illuminate\Support\Collection
;
use
Jenssegers\Mongodb\Connection
;
use
MongoDate
;
...
...
@@ -547,23 +548,24 @@ class Builder extends BaseBuilder {
}
/**
*
Pluck a single column from the database
.
*
Get an array with the values of a given column
.
*
* @param string $column
* @return mixed
* @param string|null $key
* @return array
*/
public
function
pluck
(
$column
)
public
function
pluck
(
$column
,
$key
=
null
)
{
$result
=
(
array
)
$this
->
first
([
$column
]);
//
MongoDB returns the _id field even if you did not ask for it, so we need to
//
remove this from the result.
if
(
array_key_exists
(
'_id'
,
$result
))
{
unset
(
$result
[
'_id'
]);
}
return
count
(
$result
)
>
0
?
reset
(
$result
)
:
null
;
$result
s
=
$this
->
get
(
is_null
(
$key
)
?
[
$column
]
:
[
$column
,
$key
]);
//
If the columns are qualified with a table or have an alias, we cannot use
//
those directly in the "pluck" operations since the results from the DB
// are only keyed by the column itself. We'll strip the table out here.
return
Arr
::
pluck
(
$results
,
$column
,
$key
)
;
}
/**
...
...
src/Jenssegers/Mongodb/Relations/MorphTo.php
View file @
722668de
<?php
namespace
Jenssegers\Mongodb\Relations
;
use
Illuminate\Database\Eloquent\Collection
;
use
Illuminate\Database\Eloquent\Relations\MorphTo
as
EloquentMorphTo
;
class
MorphTo
extends
EloquentMorphTo
{
...
...
tests/QueryBuilderTest.php
View file @
722668de
...
...
@@ -354,7 +354,7 @@ class QueryBuilderTest extends TestCase {
]);
$age
=
DB
::
collection
(
'users'
)
->
where
(
'name'
,
'John Doe'
)
->
pluck
(
'age'
);
$this
->
assertEquals
(
25
,
$age
);
$this
->
assertEquals
(
[
25
]
,
$age
);
}
public
function
testList
()
...
...
tests/RelationsTest.php
View file @
722668de
...
...
@@ -364,11 +364,11 @@ class RelationsTest extends TestCase {
$photos
=
Photo
::
with
(
'imageable'
)
->
get
();
$relations
=
$photos
[
0
]
->
getRelations
();
$this
->
assertTrue
(
array_key_exists
(
'imageable'
,
$relations
));
$this
->
assertInstanceOf
(
'User'
,
$
relations
[
'imageable'
]
);
$this
->
assertInstanceOf
(
'User'
,
$
photos
[
0
]
->
imageable
);
$relations
=
$photos
[
1
]
->
getRelations
();
$this
->
assertTrue
(
array_key_exists
(
'imageable'
,
$relations
));
$this
->
assertInstanceOf
(
'Client'
,
$
relations
[
'imageable'
]
);
$this
->
assertInstanceOf
(
'Client'
,
$
photos
[
1
]
->
imageable
);
}
public
function
testHasManyHas
()
...
...
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