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
76858f3c
Commit
76858f3c
authored
Jan 25, 2016
by
Jens Segers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Run PSR2 fixer
parent
f6865bae
Show whitespace changes
Inline
Side-by-side
Showing
49 changed files
with
481 additions
and
627 deletions
+481
-627
DatabaseTokenRepository.php
src/Jenssegers/Mongodb/Auth/DatabaseTokenRepository.php
+5
-8
PasswordResetServiceProvider.php
src/Jenssegers/Mongodb/Auth/PasswordResetServiceProvider.php
+3
-4
Collection.php
src/Jenssegers/Mongodb/Collection.php
+6
-11
Connection.php
src/Jenssegers/Mongodb/Connection.php
+15
-13
Builder.php
src/Jenssegers/Mongodb/Eloquent/Builder.php
+19
-26
Collection.php
src/Jenssegers/Mongodb/Eloquent/Collection.php
+6
-10
HybridRelations.php
src/Jenssegers/Mongodb/Eloquent/HybridRelations.php
+16
-29
Model.php
src/Jenssegers/Mongodb/Eloquent/Model.php
+48
-75
SoftDeletes.php
src/Jenssegers/Mongodb/Eloquent/SoftDeletes.php
+2
-2
MongodbServiceProvider.php
src/Jenssegers/Mongodb/MongodbServiceProvider.php
+4
-6
Builder.php
src/Jenssegers/Mongodb/Query/Builder.php
+124
-163
Grammar.php
src/Jenssegers/Mongodb/Query/Grammar.php
+2
-2
Processor.php
src/Jenssegers/Mongodb/Query/Processor.php
+2
-2
BelongsTo.php
src/Jenssegers/Mongodb/Relations/BelongsTo.php
+3
-4
BelongsToMany.php
src/Jenssegers/Mongodb/Relations/BelongsToMany.php
+28
-24
EmbedsMany.php
src/Jenssegers/Mongodb/Relations/EmbedsMany.php
+33
-35
EmbedsOne.php
src/Jenssegers/Mongodb/Relations/EmbedsOne.php
+15
-13
EmbedsOneOrMany.php
src/Jenssegers/Mongodb/Relations/EmbedsOneOrMany.php
+23
-29
HasMany.php
src/Jenssegers/Mongodb/Relations/HasMany.php
+2
-2
HasOne.php
src/Jenssegers/Mongodb/Relations/HasOne.php
+2
-2
MorphTo.php
src/Jenssegers/Mongodb/Relations/MorphTo.php
+3
-4
Blueprint.php
src/Jenssegers/Mongodb/Schema/Blueprint.php
+10
-20
Builder.php
src/Jenssegers/Mongodb/Schema/Builder.php
+6
-8
AuthTest.php
tests/AuthTest.php
+3
-4
ConnectionTest.php
tests/ConnectionTest.php
+2
-2
EmbeddedRelationsTest.php
tests/EmbeddedRelationsTest.php
+2
-2
ModelTest.php
tests/ModelTest.php
+8
-11
MysqlRelationsTest.php
tests/MysqlRelationsTest.php
+2
-1
QueryBuilderTest.php
tests/QueryBuilderTest.php
+8
-8
QueryTest.php
tests/QueryTest.php
+12
-22
RelationsTest.php
tests/RelationsTest.php
+4
-6
SchemaTest.php
tests/SchemaTest.php
+23
-39
SeederTest.php
tests/SeederTest.php
+2
-2
TestCase.php
tests/TestCase.php
+2
-2
ValidationTest.php
tests/ValidationTest.php
+2
-2
Address.php
tests/models/Address.php
+2
-2
Book.php
tests/models/Book.php
+2
-1
Client.php
tests/models/Client.php
+2
-1
Group.php
tests/models/Group.php
+2
-1
Item.php
tests/models/Item.php
+2
-2
MysqlBook.php
tests/models/MysqlBook.php
+4
-6
MysqlRole.php
tests/models/MysqlRole.php
+4
-6
MysqlUser.php
tests/models/MysqlUser.php
+4
-6
Photo.php
tests/models/Photo.php
+2
-2
Role.php
tests/models/Role.php
+2
-2
Soft.php
tests/models/Soft.php
+2
-2
User.php
tests/models/User.php
+2
-1
DatabaseSeeder.php
tests/seeds/DatabaseSeeder.php
+2
-1
UserTableSeeder.php
tests/seeds/UserTableSeeder.php
+2
-1
No files found.
src/Jenssegers/Mongodb/Auth/DatabaseTokenRepository.php
View file @
76858f3c
...
@@ -2,7 +2,8 @@
...
@@ -2,7 +2,8 @@
use
MongoDB\BSON\UTCDateTime
;
use
MongoDB\BSON\UTCDateTime
;
class
DatabaseTokenRepository
extends
\Illuminate\Auth\Passwords\DatabaseTokenRepository
{
class
DatabaseTokenRepository
extends
\Illuminate\Auth\Passwords\DatabaseTokenRepository
{
/**
/**
* Build the record payload for the table.
* Build the record payload for the table.
...
@@ -25,18 +26,14 @@ class DatabaseTokenRepository extends \Illuminate\Auth\Passwords\DatabaseTokenRe
...
@@ -25,18 +26,14 @@ class DatabaseTokenRepository extends \Illuminate\Auth\Passwords\DatabaseTokenRe
protected
function
tokenExpired
(
$token
)
protected
function
tokenExpired
(
$token
)
{
{
// Convert UTCDateTime to a date string.
// Convert UTCDateTime to a date string.
if
(
$token
[
'created_at'
]
instanceof
UTCDateTime
)
if
(
$token
[
'created_at'
]
instanceof
UTCDateTime
)
{
{
$date
=
$token
[
'created_at'
]
->
toDateTime
();
$date
=
$token
[
'created_at'
]
->
toDateTime
();
$token
[
'created_at'
]
=
$date
->
format
(
'Y-m-d H:i:s'
);
$token
[
'created_at'
]
=
$date
->
format
(
'Y-m-d H:i:s'
);
}
}
elseif
(
is_array
(
$token
[
'created_at'
])
and
isset
(
$token
[
'created_at'
][
'date'
]))
{
elseif
(
is_array
(
$token
[
'created_at'
])
and
isset
(
$token
[
'created_at'
][
'date'
]))
{
$token
[
'created_at'
]
=
$token
[
'created_at'
][
'date'
];
$token
[
'created_at'
]
=
$token
[
'created_at'
][
'date'
];
}
}
return
parent
::
tokenExpired
(
$token
);
return
parent
::
tokenExpired
(
$token
);
}
}
}
}
src/Jenssegers/Mongodb/Auth/PasswordResetServiceProvider.php
View file @
76858f3c
...
@@ -2,7 +2,8 @@
...
@@ -2,7 +2,8 @@
use
Jenssegers\Mongodb\Auth\DatabaseTokenRepository
as
DbRepository
;
use
Jenssegers\Mongodb\Auth\DatabaseTokenRepository
as
DbRepository
;
class
PasswordResetServiceProvider
extends
\Illuminate\Auth\Passwords\PasswordResetServiceProvider
{
class
PasswordResetServiceProvider
extends
\Illuminate\Auth\Passwords\PasswordResetServiceProvider
{
/**
/**
* Register the token repository implementation.
* Register the token repository implementation.
...
@@ -11,8 +12,7 @@ class PasswordResetServiceProvider extends \Illuminate\Auth\Passwords\PasswordRe
...
@@ -11,8 +12,7 @@ class PasswordResetServiceProvider extends \Illuminate\Auth\Passwords\PasswordRe
*/
*/
protected
function
registerTokenRepository
()
protected
function
registerTokenRepository
()
{
{
$this
->
app
->
singleton
(
'auth.password.tokens'
,
function
(
$app
)
$this
->
app
->
singleton
(
'auth.password.tokens'
,
function
(
$app
)
{
{
$connection
=
$app
[
'db'
]
->
connection
();
$connection
=
$app
[
'db'
]
->
connection
();
// The database token repository is an implementation of the token repository
// The database token repository is an implementation of the token repository
...
@@ -27,5 +27,4 @@ class PasswordResetServiceProvider extends \Illuminate\Auth\Passwords\PasswordRe
...
@@ -27,5 +27,4 @@ class PasswordResetServiceProvider extends \Illuminate\Auth\Passwords\PasswordRe
return
new
DbRepository
(
$connection
,
$table
,
$key
,
$expire
);
return
new
DbRepository
(
$connection
,
$table
,
$key
,
$expire
);
});
});
}
}
}
}
src/Jenssegers/Mongodb/Collection.php
View file @
76858f3c
...
@@ -3,7 +3,8 @@
...
@@ -3,7 +3,8 @@
use
Exception
;
use
Exception
;
use
MongoDB\Collection
as
MongoCollection
;
use
MongoDB\Collection
as
MongoCollection
;
class
Collection
{
class
Collection
{
/**
/**
* The connection instance.
* The connection instance.
...
@@ -40,8 +41,7 @@ class Collection {
...
@@ -40,8 +41,7 @@ class Collection {
$start
=
microtime
(
true
);
$start
=
microtime
(
true
);
$result
=
call_user_func_array
([
$this
->
collection
,
$method
],
$parameters
);
$result
=
call_user_func_array
([
$this
->
collection
,
$method
],
$parameters
);
if
(
$this
->
connection
->
logging
())
if
(
$this
->
connection
->
logging
())
{
{
// Once we have run the query we will calculate the time that it took to run and
// Once we have run the query we will calculate the time that it took to run and
// then log the query, bindings, and execution time so we will report them on
// then log the query, bindings, and execution time so we will report them on
// the event that the developer needs them. We'll log time in milliseconds.
// the event that the developer needs them. We'll log time in milliseconds.
...
@@ -50,14 +50,10 @@ class Collection {
...
@@ -50,14 +50,10 @@ class Collection {
$query
=
[];
$query
=
[];
// Convert the query paramters to a json string.
// Convert the query paramters to a json string.
foreach
(
$parameters
as
$parameter
)
foreach
(
$parameters
as
$parameter
)
{
{
try
{
try
{
$query
[]
=
json_encode
(
$parameter
);
$query
[]
=
json_encode
(
$parameter
);
}
}
catch
(
Exception
$e
)
{
catch
(
Exception
$e
)
{
$query
[]
=
'{...}'
;
$query
[]
=
'{...}'
;
}
}
}
}
...
@@ -69,5 +65,4 @@ class Collection {
...
@@ -69,5 +65,4 @@ class Collection {
return
$result
;
return
$result
;
}
}
}
}
src/Jenssegers/Mongodb/Connection.php
View file @
76858f3c
...
@@ -2,7 +2,8 @@
...
@@ -2,7 +2,8 @@
use
MongoDB\Client
;
use
MongoDB\Client
;
class
Connection
extends
\Illuminate\Database\Connection
{
class
Connection
extends
\Illuminate\Database\Connection
{
/**
/**
* The MongoDB database handler.
* The MongoDB database handler.
...
@@ -132,8 +133,7 @@ class Connection extends \Illuminate\Database\Connection {
...
@@ -132,8 +133,7 @@ class Connection extends \Illuminate\Database\Connection {
// By default driver options is an empty array.
// By default driver options is an empty array.
$driverOptions
=
[];
$driverOptions
=
[];
if
(
isset
(
$config
[
'driver_options'
])
&&
is_array
(
$config
[
'driver_options'
]))
if
(
isset
(
$config
[
'driver_options'
])
&&
is_array
(
$config
[
'driver_options'
]))
{
{
$driverOptions
=
$config
[
'driver_options'
];
$driverOptions
=
$config
[
'driver_options'
];
}
}
...
@@ -162,19 +162,16 @@ class Connection extends \Illuminate\Database\Connection {
...
@@ -162,19 +162,16 @@ class Connection extends \Illuminate\Database\Connection {
extract
(
$config
);
extract
(
$config
);
// Check if the user passed a complete dsn to the configuration.
// Check if the user passed a complete dsn to the configuration.
if
(
!
empty
(
$dsn
))
if
(
!
empty
(
$dsn
))
{
{
return
$dsn
;
return
$dsn
;
}
}
// Treat host option as array of hosts
// Treat host option as array of hosts
$hosts
=
is_array
(
$host
)
?
$host
:
[
$host
];
$hosts
=
is_array
(
$host
)
?
$host
:
[
$host
];
foreach
(
$hosts
as
&
$host
)
foreach
(
$hosts
as
&
$host
)
{
{
// Check if we need to add a port to the host
// Check if we need to add a port to the host
if
(
strpos
(
$host
,
':'
)
===
false
and
isset
(
$port
))
if
(
strpos
(
$host
,
':'
)
===
false
and
isset
(
$port
))
{
{
$host
=
"
{
$host
}
:
{
$port
}
"
;
$host
=
"
{
$host
}
:
{
$port
}
"
;
}
}
}
}
...
@@ -182,9 +179,15 @@ class Connection extends \Illuminate\Database\Connection {
...
@@ -182,9 +179,15 @@ class Connection extends \Illuminate\Database\Connection {
// The database name needs to be in the connection string, otherwise it will
// The database name needs to be in the connection string, otherwise it will
// authenticate to the admin database, which may result in permission errors.
// authenticate to the admin database, which may result in permission errors.
$auth
=
''
;
$auth
=
''
;
if
(
!
empty
(
$username
))
$auth
.=
$username
;
if
(
!
empty
(
$username
))
{
if
(
!
empty
(
$password
))
$auth
.=
':'
.
$password
;
$auth
.=
$username
;
if
(
$auth
)
$auth
.=
'@'
;
}
if
(
!
empty
(
$password
))
{
$auth
.=
':'
.
$password
;
}
if
(
$auth
)
{
$auth
.=
'@'
;
}
return
"mongodb://"
.
$auth
.
implode
(
','
,
$hosts
)
.
"/
{
$database
}
"
;
return
"mongodb://"
.
$auth
.
implode
(
','
,
$hosts
)
.
"/
{
$database
}
"
;
}
}
...
@@ -221,5 +224,4 @@ class Connection extends \Illuminate\Database\Connection {
...
@@ -221,5 +224,4 @@ class Connection extends \Illuminate\Database\Connection {
{
{
return
call_user_func_array
([
$this
->
db
,
$method
],
$parameters
);
return
call_user_func_array
([
$this
->
db
,
$method
],
$parameters
);
}
}
}
}
src/Jenssegers/Mongodb/Eloquent/Builder.php
View file @
76858f3c
...
@@ -5,7 +5,8 @@ use Illuminate\Database\Eloquent\Relations\Relation;
...
@@ -5,7 +5,8 @@ use Illuminate\Database\Eloquent\Relations\Relation;
use
MongoDB\Driver\Cursor
;
use
MongoDB\Driver\Cursor
;
use
MongoDB\Model\BSONDocument
;
use
MongoDB\Model\BSONDocument
;
class
Builder
extends
EloquentBuilder
{
class
Builder
extends
EloquentBuilder
{
/**
/**
* The methods that should be returned from query builder.
* The methods that should be returned from query builder.
...
@@ -27,8 +28,7 @@ class Builder extends EloquentBuilder {
...
@@ -27,8 +28,7 @@ class Builder extends EloquentBuilder {
{
{
// Intercept operations on embedded models and delegate logic
// Intercept operations on embedded models and delegate logic
// to the parent relation instance.
// to the parent relation instance.
if
(
$relation
=
$this
->
model
->
getParentRelation
())
if
(
$relation
=
$this
->
model
->
getParentRelation
())
{
{
$relation
->
performUpdate
(
$this
->
model
,
$values
);
$relation
->
performUpdate
(
$this
->
model
,
$values
);
return
1
;
return
1
;
...
@@ -47,8 +47,7 @@ class Builder extends EloquentBuilder {
...
@@ -47,8 +47,7 @@ class Builder extends EloquentBuilder {
{
{
// Intercept operations on embedded models and delegate logic
// Intercept operations on embedded models and delegate logic
// to the parent relation instance.
// to the parent relation instance.
if
(
$relation
=
$this
->
model
->
getParentRelation
())
if
(
$relation
=
$this
->
model
->
getParentRelation
())
{
{
$relation
->
performInsert
(
$this
->
model
,
$values
);
$relation
->
performInsert
(
$this
->
model
,
$values
);
return
true
;
return
true
;
...
@@ -68,8 +67,7 @@ class Builder extends EloquentBuilder {
...
@@ -68,8 +67,7 @@ class Builder extends EloquentBuilder {
{
{
// Intercept operations on embedded models and delegate logic
// Intercept operations on embedded models and delegate logic
// to the parent relation instance.
// to the parent relation instance.
if
(
$relation
=
$this
->
model
->
getParentRelation
())
if
(
$relation
=
$this
->
model
->
getParentRelation
())
{
{
$relation
->
performInsert
(
$this
->
model
,
$values
);
$relation
->
performInsert
(
$this
->
model
,
$values
);
return
$this
->
model
->
getKey
();
return
$this
->
model
->
getKey
();
...
@@ -87,8 +85,7 @@ class Builder extends EloquentBuilder {
...
@@ -87,8 +85,7 @@ class Builder extends EloquentBuilder {
{
{
// Intercept operations on embedded models and delegate logic
// Intercept operations on embedded models and delegate logic
// to the parent relation instance.
// to the parent relation instance.
if
(
$relation
=
$this
->
model
->
getParentRelation
())
if
(
$relation
=
$this
->
model
->
getParentRelation
())
{
{
$relation
->
performDelete
(
$this
->
model
);
$relation
->
performDelete
(
$this
->
model
);
return
$this
->
model
->
getKey
();
return
$this
->
model
->
getKey
();
...
@@ -109,8 +106,7 @@ class Builder extends EloquentBuilder {
...
@@ -109,8 +106,7 @@ class Builder extends EloquentBuilder {
{
{
// Intercept operations on embedded models and delegate logic
// Intercept operations on embedded models and delegate logic
// to the parent relation instance.
// to the parent relation instance.
if
(
$relation
=
$this
->
model
->
getParentRelation
())
if
(
$relation
=
$this
->
model
->
getParentRelation
())
{
{
$value
=
$this
->
model
->
{
$column
};
$value
=
$this
->
model
->
{
$column
};
// When doing increment and decrements, Eloquent will automatically
// When doing increment and decrements, Eloquent will automatically
...
@@ -140,8 +136,7 @@ class Builder extends EloquentBuilder {
...
@@ -140,8 +136,7 @@ class Builder extends EloquentBuilder {
{
{
// Intercept operations on embedded models and delegate logic
// Intercept operations on embedded models and delegate logic
// to the parent relation instance.
// to the parent relation instance.
if
(
$relation
=
$this
->
model
->
getParentRelation
())
if
(
$relation
=
$this
->
model
->
getParentRelation
())
{
{
$value
=
$this
->
model
->
{
$column
};
$value
=
$this
->
model
->
{
$column
};
// When doing increment and decrements, Eloquent will automatically
// When doing increment and decrements, Eloquent will automatically
...
@@ -175,13 +170,13 @@ class Builder extends EloquentBuilder {
...
@@ -175,13 +170,13 @@ class Builder extends EloquentBuilder {
$relationCount
=
array_count_values
(
$query
->
lists
(
$relation
->
getHasCompareKey
()));
$relationCount
=
array_count_values
(
$query
->
lists
(
$relation
->
getHasCompareKey
()));
// Remove unwanted related objects based on the operator and count.
// Remove unwanted related objects based on the operator and count.
$relationCount
=
array_filter
(
$relationCount
,
function
(
$counted
)
use
(
$count
,
$operator
)
$relationCount
=
array_filter
(
$relationCount
,
function
(
$counted
)
use
(
$count
,
$operator
)
{
{
// If we are comparing to 0, we always need all results.
// If we are comparing to 0, we always need all results.
if
(
$count
==
0
)
return
true
;
if
(
$count
==
0
)
{
return
true
;
}
switch
(
$operator
)
switch
(
$operator
)
{
{
case
'>='
:
case
'>='
:
case
'<'
:
case
'<'
:
return
$counted
>=
$count
;
return
$counted
>=
$count
;
...
@@ -198,7 +193,9 @@ class Builder extends EloquentBuilder {
...
@@ -198,7 +193,9 @@ class Builder extends EloquentBuilder {
$not
=
in_array
(
$operator
,
[
'<'
,
'<='
,
'!='
]);
$not
=
in_array
(
$operator
,
[
'<'
,
'<='
,
'!='
]);
// If we are comparing to 0, we need an additional $not flip.
// If we are comparing to 0, we need an additional $not flip.
if
(
$count
==
0
)
$not
=
!
$not
;
if
(
$count
==
0
)
{
$not
=
!
$not
;
}
// All related ids.
// All related ids.
$relatedIds
=
array_keys
(
$relationCount
);
$relatedIds
=
array_keys
(
$relationCount
);
...
@@ -219,26 +216,22 @@ class Builder extends EloquentBuilder {
...
@@ -219,26 +216,22 @@ class Builder extends EloquentBuilder {
$results
=
$this
->
query
->
raw
(
$expression
);
$results
=
$this
->
query
->
raw
(
$expression
);
// Convert MongoCursor results to a collection of models.
// Convert MongoCursor results to a collection of models.
if
(
$results
instanceof
Cursor
)
if
(
$results
instanceof
Cursor
)
{
{
$results
=
iterator_to_array
(
$results
,
false
);
$results
=
iterator_to_array
(
$results
,
false
);
return
$this
->
model
->
hydrate
(
$results
);
return
$this
->
model
->
hydrate
(
$results
);
}
}
// Convert Mongo BSONDocument to a single object.
// Convert Mongo BSONDocument to a single object.
elseif
(
$results
instanceof
BSONDocument
)
elseif
(
$results
instanceof
BSONDocument
)
{
{
$results
=
$results
->
getArrayCopy
();
$results
=
$results
->
getArrayCopy
();
return
$this
->
model
->
newFromBuilder
((
array
)
$results
);
return
$this
->
model
->
newFromBuilder
((
array
)
$results
);
}
}
// The result is a single object.
// The result is a single object.
elseif
(
is_array
(
$results
)
and
array_key_exists
(
'_id'
,
$results
))
elseif
(
is_array
(
$results
)
and
array_key_exists
(
'_id'
,
$results
))
{
{
return
$this
->
model
->
newFromBuilder
((
array
)
$results
);
return
$this
->
model
->
newFromBuilder
((
array
)
$results
);
}
}
return
$results
;
return
$results
;
}
}
}
}
src/Jenssegers/Mongodb/Eloquent/Collection.php
View file @
76858f3c
...
@@ -2,7 +2,8 @@
...
@@ -2,7 +2,8 @@
use
Illuminate\Database\Eloquent\Collection
as
EloquentCollection
;
use
Illuminate\Database\Eloquent\Collection
as
EloquentCollection
;
class
Collection
extends
EloquentCollection
{
class
Collection
extends
EloquentCollection
{
/**
/**
* Simulate a get clause on the collection.
* Simulate a get clause on the collection.
...
@@ -13,8 +14,7 @@ class Collection extends EloquentCollection {
...
@@ -13,8 +14,7 @@ class Collection extends EloquentCollection {
*/
*/
public
function
get
(
$key
=
null
,
$default
=
null
)
public
function
get
(
$key
=
null
,
$default
=
null
)
{
{
if
(
is_null
(
$key
)
and
is_null
(
$default
))
if
(
is_null
(
$key
)
and
is_null
(
$default
))
{
{
return
$this
;
return
$this
;
}
}
...
@@ -35,17 +35,14 @@ class Collection extends EloquentCollection {
...
@@ -35,17 +35,14 @@ class Collection extends EloquentCollection {
// Here we will make some assumptions about the operator. If only 2 values are
// Here we will make some assumptions about the operator. If only 2 values are
// passed to the method, we will assume that the operator is an equals sign
// passed to the method, we will assume that the operator is an equals sign
// and keep going.
// and keep going.
if
(
func_num_args
()
==
2
)
if
(
func_num_args
()
==
2
)
{
{
list
(
$value
,
$operator
)
=
[
$operator
,
'='
];
list
(
$value
,
$operator
)
=
[
$operator
,
'='
];
}
}
return
$this
->
filter
(
function
(
$item
)
use
(
$key
,
$operator
,
$value
)
return
$this
->
filter
(
function
(
$item
)
use
(
$key
,
$operator
,
$value
)
{
{
$actual
=
$item
->
{
$key
};
$actual
=
$item
->
{
$key
};
switch
(
$operator
)
switch
(
$operator
)
{
{
case
'<>'
:
case
'<>'
:
case
'!='
:
case
'!='
:
return
$actual
!=
$value
;
return
$actual
!=
$value
;
...
@@ -244,5 +241,4 @@ class Collection extends EloquentCollection {
...
@@ -244,5 +241,4 @@ class Collection extends EloquentCollection {
{
{
return
$this
->
take
(
$value
);
return
$this
->
take
(
$value
);
}
}
}
}
src/Jenssegers/Mongodb/Eloquent/HybridRelations.php
View file @
76858f3c
...
@@ -9,7 +9,8 @@ use Jenssegers\Mongodb\Relations\HasMany;
...
@@ -9,7 +9,8 @@ use Jenssegers\Mongodb\Relations\HasMany;
use
Jenssegers\Mongodb\Relations\HasOne
;
use
Jenssegers\Mongodb\Relations\HasOne
;
use
Jenssegers\Mongodb\Relations\MorphTo
;
use
Jenssegers\Mongodb\Relations\MorphTo
;
trait
HybridRelations
{
trait
HybridRelations
{
/**
/**
* Define a one-to-one relationship.
* Define a one-to-one relationship.
...
@@ -22,8 +23,7 @@ trait HybridRelations {
...
@@ -22,8 +23,7 @@ trait HybridRelations {
public
function
hasOne
(
$related
,
$foreignKey
=
null
,
$localKey
=
null
)
public
function
hasOne
(
$related
,
$foreignKey
=
null
,
$localKey
=
null
)
{
{
// Check if it is a relation with an original model.
// Check if it is a relation with an original model.
if
(
!
is_subclass_of
(
$related
,
'Jenssegers\Mongodb\Eloquent\Model'
))
if
(
!
is_subclass_of
(
$related
,
'Jenssegers\Mongodb\Eloquent\Model'
))
{
{
return
parent
::
hasOne
(
$related
,
$foreignKey
,
$localKey
);
return
parent
::
hasOne
(
$related
,
$foreignKey
,
$localKey
);
}
}
...
@@ -49,9 +49,8 @@ trait HybridRelations {
...
@@ -49,9 +49,8 @@ trait HybridRelations {
public
function
morphOne
(
$related
,
$name
,
$type
=
null
,
$id
=
null
,
$localKey
=
null
)
public
function
morphOne
(
$related
,
$name
,
$type
=
null
,
$id
=
null
,
$localKey
=
null
)
{
{
// Check if it is a relation with an original model.
// Check if it is a relation with an original model.
if
(
!
is_subclass_of
(
$related
,
'Jenssegers\Mongodb\Eloquent\Model'
))
if
(
!
is_subclass_of
(
$related
,
'Jenssegers\Mongodb\Eloquent\Model'
))
{
{
return
parent
::
morphOne
(
$related
,
$name
,
$type
,
$id
,
$localKey
);
return
parent
::
morphOne
(
$related
,
$name
,
$type
,
$id
,
$localKey
);
}
}
$instance
=
new
$related
;
$instance
=
new
$related
;
...
@@ -76,8 +75,7 @@ trait HybridRelations {
...
@@ -76,8 +75,7 @@ trait HybridRelations {
public
function
hasMany
(
$related
,
$foreignKey
=
null
,
$localKey
=
null
)
public
function
hasMany
(
$related
,
$foreignKey
=
null
,
$localKey
=
null
)
{
{
// Check if it is a relation with an original model.
// Check if it is a relation with an original model.
if
(
!
is_subclass_of
(
$related
,
'Jenssegers\Mongodb\Eloquent\Model'
))
if
(
!
is_subclass_of
(
$related
,
'Jenssegers\Mongodb\Eloquent\Model'
))
{
{
return
parent
::
hasMany
(
$related
,
$foreignKey
,
$localKey
);
return
parent
::
hasMany
(
$related
,
$foreignKey
,
$localKey
);
}
}
...
@@ -103,8 +101,7 @@ trait HybridRelations {
...
@@ -103,8 +101,7 @@ trait HybridRelations {
public
function
morphMany
(
$related
,
$name
,
$type
=
null
,
$id
=
null
,
$localKey
=
null
)
public
function
morphMany
(
$related
,
$name
,
$type
=
null
,
$id
=
null
,
$localKey
=
null
)
{
{
// Check if it is a relation with an original model.
// Check if it is a relation with an original model.
if
(
!
is_subclass_of
(
$related
,
'Jenssegers\Mongodb\Eloquent\Model'
))
if
(
!
is_subclass_of
(
$related
,
'Jenssegers\Mongodb\Eloquent\Model'
))
{
{
return
parent
::
morphMany
(
$related
,
$name
,
$type
,
$id
,
$localKey
);
return
parent
::
morphMany
(
$related
,
$name
,
$type
,
$id
,
$localKey
);
}
}
...
@@ -136,24 +133,21 @@ trait HybridRelations {
...
@@ -136,24 +133,21 @@ trait HybridRelations {
// If no relation name was given, we will use this debug backtrace to extract
// 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
// 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 relationships.
// of the time this will be what we desire to use for the relationships.
if
(
is_null
(
$relation
))
if
(
is_null
(
$relation
))
{
{
list
(
$current
,
$caller
)
=
debug_backtrace
(
false
,
2
);
list
(
$current
,
$caller
)
=
debug_backtrace
(
false
,
2
);
$relation
=
$caller
[
'function'
];
$relation
=
$caller
[
'function'
];
}
}
// Check if it is a relation with an original model.
// Check if it is a relation with an original model.
if
(
!
is_subclass_of
(
$related
,
'Jenssegers\Mongodb\Eloquent\Model'
))
if
(
!
is_subclass_of
(
$related
,
'Jenssegers\Mongodb\Eloquent\Model'
))
{
{
return
parent
::
belongsTo
(
$related
,
$foreignKey
,
$otherKey
,
$relation
);
return
parent
::
belongsTo
(
$related
,
$foreignKey
,
$otherKey
,
$relation
);
}
}
// If no foreign key was supplied, we can use a backtrace to guess the proper
// If no foreign key was supplied, we can use a backtrace to guess the proper
// foreign key name by using the name of the relationship function, which
// foreign key name by using the name of the relationship function, which
// when combined with an "_id" should conventionally match the columns.
// when combined with an "_id" should conventionally match the columns.
if
(
is_null
(
$foreignKey
))
if
(
is_null
(
$foreignKey
))
{
{
$foreignKey
=
Str
::
snake
(
$relation
)
.
'_id'
;
$foreignKey
=
Str
::
snake
(
$relation
)
.
'_id'
;
}
}
...
@@ -182,8 +176,7 @@ trait HybridRelations {
...
@@ -182,8 +176,7 @@ trait HybridRelations {
// If no name is provided, we will use the backtrace to get the function name
// If no name is provided, we will use the backtrace to get the function name
// since that is most likely the name of the polymorphic interface. We can
// since that is most likely the name of the polymorphic interface. We can
// use that to get both the class and foreign key that will be utilized.
// use that to get both the class and foreign key that will be utilized.
if
(
is_null
(
$name
))
if
(
is_null
(
$name
))
{
{
list
(
$current
,
$caller
)
=
debug_backtrace
(
DEBUG_BACKTRACE_IGNORE_ARGS
,
2
);
list
(
$current
,
$caller
)
=
debug_backtrace
(
DEBUG_BACKTRACE_IGNORE_ARGS
,
2
);
$name
=
Str
::
snake
(
$caller
[
'function'
]);
$name
=
Str
::
snake
(
$caller
[
'function'
]);
...
@@ -194,8 +187,7 @@ trait HybridRelations {
...
@@ -194,8 +187,7 @@ trait HybridRelations {
// If the type value is null it is probably safe to assume we're eager loading
// If the type value is null it is probably safe to assume we're eager loading
// the relationship. When that is the case we will pass in a dummy query as
// the relationship. When that is the case we will pass in a dummy query as
// there are multiple types in the morph and we can't use single queries.
// there are multiple types in the morph and we can't use single queries.
if
(
is_null
(
$class
=
$this
->
$type
))
if
(
is_null
(
$class
=
$this
->
$type
))
{
{
return
new
MorphTo
(
return
new
MorphTo
(
$this
->
newQuery
(),
$this
,
$id
,
null
,
$type
,
$name
$this
->
newQuery
(),
$this
,
$id
,
null
,
$type
,
$name
);
);
...
@@ -204,8 +196,7 @@ trait HybridRelations {
...
@@ -204,8 +196,7 @@ trait HybridRelations {
// If we are not eager loading the relationship we will essentially treat this
// If we are not eager loading the relationship we will essentially treat this
// as a belongs-to style relationship since morph-to extends that class and
// 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.
// we will pass in the appropriate values so that it behaves as expected.
else
else
{
{
$class
=
$this
->
getActualClassNameForMorph
(
$class
);
$class
=
$this
->
getActualClassNameForMorph
(
$class
);
$instance
=
new
$class
;
$instance
=
new
$class
;
...
@@ -231,14 +222,12 @@ trait HybridRelations {
...
@@ -231,14 +222,12 @@ trait HybridRelations {
// If no relationship name was passed, we will pull backtraces to get the
// If no relationship name was passed, we will pull backtraces to get the
// name of the calling function. We will use that function name as the
// name of the calling function. We will use that function name as the
// title of this relation since that is a great convention to apply.
// title of this relation since that is a great convention to apply.
if
(
is_null
(
$relation
))
if
(
is_null
(
$relation
))
{
{
$relation
=
$this
->
getBelongsToManyCaller
();
$relation
=
$this
->
getBelongsToManyCaller
();
}
}
// Check if it is a relation with an original model.
// Check if it is a relation with an original model.
if
(
!
is_subclass_of
(
$related
,
'Jenssegers\Mongodb\Eloquent\Model'
))
if
(
!
is_subclass_of
(
$related
,
'Jenssegers\Mongodb\Eloquent\Model'
))
{
{
return
parent
::
belongsToMany
(
$related
,
$collection
,
$foreignKey
,
$otherKey
,
$relation
);
return
parent
::
belongsToMany
(
$related
,
$collection
,
$foreignKey
,
$otherKey
,
$relation
);
}
}
...
@@ -254,8 +243,7 @@ trait HybridRelations {
...
@@ -254,8 +243,7 @@ trait HybridRelations {
// If no table name was provided, we can guess it by concatenating the two
// If no table name was provided, we can guess it by concatenating the two
// models using underscores in alphabetical order. The two model names
// models using underscores in alphabetical order. The two model names
// are transformed to snake case from their default CamelCase also.
// are transformed to snake case from their default CamelCase also.
if
(
is_null
(
$collection
))
if
(
is_null
(
$collection
))
{
{
$collection
=
$instance
->
getTable
();
$collection
=
$instance
->
getTable
();
}
}
...
@@ -266,5 +254,4 @@ trait HybridRelations {
...
@@ -266,5 +254,4 @@ trait HybridRelations {
return
new
BelongsToMany
(
$query
,
$this
,
$collection
,
$foreignKey
,
$otherKey
,
$relation
);
return
new
BelongsToMany
(
$query
,
$this
,
$collection
,
$foreignKey
,
$otherKey
,
$relation
);
}
}
}
}
src/Jenssegers/Mongodb/Eloquent/Model.php
View file @
76858f3c
...
@@ -12,7 +12,8 @@ use MongoDB\BSON\ObjectID;
...
@@ -12,7 +12,8 @@ use MongoDB\BSON\ObjectID;
use
MongoDB\BSON\UTCDateTime
;
use
MongoDB\BSON\UTCDateTime
;
use
ReflectionMethod
;
use
ReflectionMethod
;
abstract
class
Model
extends
BaseModel
{
abstract
class
Model
extends
BaseModel
{
use
HybridRelations
;
use
HybridRelations
;
...
@@ -47,14 +48,12 @@ abstract class Model extends BaseModel {
...
@@ -47,14 +48,12 @@ abstract class Model extends BaseModel {
{
{
// If we don't have a value for 'id', we will use the Mongo '_id' value.
// If we don't have a value for 'id', we will use the Mongo '_id' value.
// This allows us to work with models in a more sql-like way.
// This allows us to work with models in a more sql-like way.
if
(
!
$value
and
array_key_exists
(
'_id'
,
$this
->
attributes
))
if
(
!
$value
and
array_key_exists
(
'_id'
,
$this
->
attributes
))
{
{
$value
=
$this
->
attributes
[
'_id'
];
$value
=
$this
->
attributes
[
'_id'
];
}
}
// Convert ObjectID to string.
// Convert ObjectID to string.
if
(
$value
instanceof
ObjectID
)
if
(
$value
instanceof
ObjectID
)
{
{
return
(
string
)
$value
;
return
(
string
)
$value
;
}
}
...
@@ -85,20 +84,17 @@ abstract class Model extends BaseModel {
...
@@ -85,20 +84,17 @@ abstract class Model extends BaseModel {
// If no relation name was given, we will use this debug backtrace to extract
// 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
// 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 relatinoships.
// of the time this will be what we desire to use for the relatinoships.
if
(
is_null
(
$relation
))
if
(
is_null
(
$relation
))
{
{
list
(,
$caller
)
=
debug_backtrace
(
false
);
list
(,
$caller
)
=
debug_backtrace
(
false
);
$relation
=
$caller
[
'function'
];
$relation
=
$caller
[
'function'
];
}
}
if
(
is_null
(
$localKey
))
if
(
is_null
(
$localKey
))
{
{
$localKey
=
$relation
;
$localKey
=
$relation
;
}
}
if
(
is_null
(
$foreignKey
))
if
(
is_null
(
$foreignKey
))
{
{
$foreignKey
=
snake_case
(
class_basename
(
$this
));
$foreignKey
=
snake_case
(
class_basename
(
$this
));
}
}
...
@@ -123,20 +119,17 @@ abstract class Model extends BaseModel {
...
@@ -123,20 +119,17 @@ abstract class Model extends BaseModel {
// If no relation name was given, we will use this debug backtrace to extract
// 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
// 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 relatinoships.
// of the time this will be what we desire to use for the relatinoships.
if
(
is_null
(
$relation
))
if
(
is_null
(
$relation
))
{
{
list
(,
$caller
)
=
debug_backtrace
(
false
);
list
(,
$caller
)
=
debug_backtrace
(
false
);
$relation
=
$caller
[
'function'
];
$relation
=
$caller
[
'function'
];
}
}
if
(
is_null
(
$localKey
))
if
(
is_null
(
$localKey
))
{
{
$localKey
=
$relation
;
$localKey
=
$relation
;
}
}
if
(
is_null
(
$foreignKey
))
if
(
is_null
(
$foreignKey
))
{
{
$foreignKey
=
snake_case
(
class_basename
(
$this
));
$foreignKey
=
snake_case
(
class_basename
(
$this
));
}
}
...
@@ -156,14 +149,12 @@ abstract class Model extends BaseModel {
...
@@ -156,14 +149,12 @@ abstract class Model extends BaseModel {
public
function
fromDateTime
(
$value
)
public
function
fromDateTime
(
$value
)
{
{
// If the value is already a UTCDateTime instance, we don't need to parse it.
// If the value is already a UTCDateTime instance, we don't need to parse it.
if
(
$value
instanceof
UTCDateTime
)
if
(
$value
instanceof
UTCDateTime
)
{
{
return
$value
;
return
$value
;
}
}
// Let Eloquent convert the value to a DateTime instance.
// Let Eloquent convert the value to a DateTime instance.
if
(
!
$value
instanceof
DateTime
)
if
(
!
$value
instanceof
DateTime
)
{
{
$value
=
parent
::
asDateTime
(
$value
);
$value
=
parent
::
asDateTime
(
$value
);
}
}
...
@@ -179,8 +170,7 @@ abstract class Model extends BaseModel {
...
@@ -179,8 +170,7 @@ abstract class Model extends BaseModel {
protected
function
asDateTime
(
$value
)
protected
function
asDateTime
(
$value
)
{
{
// Convert UTCDateTime instances.
// Convert UTCDateTime instances.
if
(
$value
instanceof
UTCDateTime
)
if
(
$value
instanceof
UTCDateTime
)
{
{
return
Carbon
::
createFromTimestamp
(
$value
->
toDateTime
()
->
getTimestamp
());
return
Carbon
::
createFromTimestamp
(
$value
->
toDateTime
()
->
getTimestamp
());
}
}
...
@@ -226,8 +216,7 @@ abstract class Model extends BaseModel {
...
@@ -226,8 +216,7 @@ abstract class Model extends BaseModel {
public
function
getAttribute
(
$key
)
public
function
getAttribute
(
$key
)
{
{
// Check if the key is an array dot notation.
// Check if the key is an array dot notation.
if
(
str_contains
(
$key
,
'.'
)
and
array_has
(
$this
->
attributes
,
$key
))
if
(
str_contains
(
$key
,
'.'
)
and
array_has
(
$this
->
attributes
,
$key
))
{
{
return
$this
->
getAttributeValue
(
$key
);
return
$this
->
getAttributeValue
(
$key
);
}
}
...
@@ -236,24 +225,20 @@ abstract class Model extends BaseModel {
...
@@ -236,24 +225,20 @@ abstract class Model extends BaseModel {
// If the "attribute" exists as a method on the model, it may be an
// If the "attribute" exists as a method on the model, it may be an
// embedded model. If so, we need to return the result before it
// embedded model. If so, we need to return the result before it
// is handled by the parent method.
// is handled by the parent method.
if
(
method_exists
(
$this
,
$camelKey
))
if
(
method_exists
(
$this
,
$camelKey
))
{
{
$method
=
new
ReflectionMethod
(
get_called_class
(),
$camelKey
);
$method
=
new
ReflectionMethod
(
get_called_class
(),
$camelKey
);
// Ensure the method is not static to avoid conflicting with Eloquent methods.
// Ensure the method is not static to avoid conflicting with Eloquent methods.
if
(
!
$method
->
isStatic
())
if
(
!
$method
->
isStatic
())
{
{
$relations
=
$this
->
$camelKey
();
$relations
=
$this
->
$camelKey
();
// This attribute matches an embedsOne or embedsMany relation so we need
// This attribute matches an embedsOne or embedsMany relation so we need
// to return the relation results instead of the interal attributes.
// to return the relation results instead of the interal attributes.
if
(
$relations
instanceof
EmbedsOneOrMany
)
if
(
$relations
instanceof
EmbedsOneOrMany
)
{
{
// If the key already exists in the relationships array, it just means the
// If the key already exists in the relationships array, it just means the
// relationship has already been loaded, so we'll just return it out of
// relationship has already been loaded, so we'll just return it out of
// here because there is no need to query within the relations twice.
// here because there is no need to query within the relations twice.
if
(
array_key_exists
(
$key
,
$this
->
relations
))
if
(
array_key_exists
(
$key
,
$this
->
relations
))
{
{
return
$this
->
relations
[
$key
];
return
$this
->
relations
[
$key
];
}
}
...
@@ -275,12 +260,10 @@ abstract class Model extends BaseModel {
...
@@ -275,12 +260,10 @@ abstract class Model extends BaseModel {
protected
function
getAttributeFromArray
(
$key
)
protected
function
getAttributeFromArray
(
$key
)
{
{
// Support keys in dot notation.
// Support keys in dot notation.
if
(
str_contains
(
$key
,
'.'
))
if
(
str_contains
(
$key
,
'.'
))
{
{
$attributes
=
array_dot
(
$this
->
attributes
);
$attributes
=
array_dot
(
$this
->
attributes
);
if
(
array_key_exists
(
$key
,
$attributes
))
if
(
array_key_exists
(
$key
,
$attributes
))
{
{
return
$attributes
[
$key
];
return
$attributes
[
$key
];
}
}
}
}
...
@@ -297,18 +280,15 @@ abstract class Model extends BaseModel {
...
@@ -297,18 +280,15 @@ abstract class Model extends BaseModel {
public
function
setAttribute
(
$key
,
$value
)
public
function
setAttribute
(
$key
,
$value
)
{
{
// Convert _id to ObjectID.
// Convert _id to ObjectID.
if
(
$key
==
'_id'
and
is_string
(
$value
))
if
(
$key
==
'_id'
and
is_string
(
$value
))
{
{
$builder
=
$this
->
newBaseQueryBuilder
();
$builder
=
$this
->
newBaseQueryBuilder
();
$value
=
$builder
->
convertKey
(
$value
);
$value
=
$builder
->
convertKey
(
$value
);
}
}
// Support keys in dot notation.
// Support keys in dot notation.
elseif
(
str_contains
(
$key
,
'.'
))
elseif
(
str_contains
(
$key
,
'.'
))
{
{
if
(
in_array
(
$key
,
$this
->
getDates
())
&&
$value
)
{
if
(
in_array
(
$key
,
$this
->
getDates
())
&&
$value
)
{
$value
=
$this
->
fromDateTime
(
$value
);
$value
=
$this
->
fromDateTime
(
$value
);
}
}
...
@@ -333,19 +313,15 @@ abstract class Model extends BaseModel {
...
@@ -333,19 +313,15 @@ abstract class Model extends BaseModel {
// 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
$key
=>
&
$value
)
foreach
(
$attributes
as
$key
=>
&
$value
)
{
{
if
(
$value
instanceof
ObjectID
)
{
if
(
$value
instanceof
ObjectID
)
{
$value
=
(
string
)
$value
;
$value
=
(
string
)
$value
;
}
}
}
}
// Convert dot-notation dates.
// Convert dot-notation dates.
foreach
(
$this
->
getDates
()
as
$key
)
foreach
(
$this
->
getDates
()
as
$key
)
{
{
if
(
str_contains
(
$key
,
'.'
)
and
array_has
(
$attributes
,
$key
))
{
if
(
str_contains
(
$key
,
'.'
)
and
array_has
(
$attributes
,
$key
))
{
array_set
(
$attributes
,
$key
,
(
string
)
$this
->
asDateTime
(
array_get
(
$attributes
,
$key
)));
array_set
(
$attributes
,
$key
,
(
string
)
$this
->
asDateTime
(
array_get
(
$attributes
,
$key
)));
}
}
}
}
...
@@ -375,8 +351,7 @@ abstract class Model extends BaseModel {
...
@@ -375,8 +351,7 @@ abstract class Model extends BaseModel {
$original
=
$this
->
original
[
$key
];
$original
=
$this
->
original
[
$key
];
// Date comparison.
// Date comparison.
if
(
in_array
(
$key
,
$this
->
getDates
()))
if
(
in_array
(
$key
,
$this
->
getDates
()))
{
{
$current
=
$current
instanceof
UTCDateTime
?
$this
->
asDateTime
(
$current
)
:
$current
;
$current
=
$current
instanceof
UTCDateTime
?
$this
->
asDateTime
(
$current
)
:
$current
;
$original
=
$original
instanceof
UTCDateTime
?
$this
->
asDateTime
(
$original
)
:
$original
;
$original
=
$original
instanceof
UTCDateTime
?
$this
->
asDateTime
(
$original
)
:
$original
;
...
@@ -394,11 +369,12 @@ abstract class Model extends BaseModel {
...
@@ -394,11 +369,12 @@ abstract class Model extends BaseModel {
*/
*/
public
function
drop
(
$columns
)
public
function
drop
(
$columns
)
{
{
if
(
!
is_array
(
$columns
))
$columns
=
[
$columns
];
if
(
!
is_array
(
$columns
))
{
$columns
=
[
$columns
];
}
// Unset attributes
// Unset attributes
foreach
(
$columns
as
$column
)
foreach
(
$columns
as
$column
)
{
{
$this
->
__unset
(
$column
);
$this
->
__unset
(
$column
);
}
}
...
@@ -413,21 +389,19 @@ abstract class Model extends BaseModel {
...
@@ -413,21 +389,19 @@ abstract class Model extends BaseModel {
*/
*/
public
function
push
()
public
function
push
()
{
{
if
(
$parameters
=
func_get_args
())
if
(
$parameters
=
func_get_args
())
{
{
$unique
=
false
;
$unique
=
false
;
if
(
count
(
$parameters
)
==
3
)
if
(
count
(
$parameters
)
==
3
)
{
{
list
(
$column
,
$values
,
$unique
)
=
$parameters
;
list
(
$column
,
$values
,
$unique
)
=
$parameters
;
}
}
else
{
else
{
list
(
$column
,
$values
)
=
$parameters
;
list
(
$column
,
$values
)
=
$parameters
;
}
}
// Do batch push by default.
// Do batch push by default.
if
(
!
is_array
(
$values
))
$values
=
[
$values
];
if
(
!
is_array
(
$values
))
{
$values
=
[
$values
];
}
$query
=
$this
->
setKeysForSaveQuery
(
$this
->
newQuery
());
$query
=
$this
->
setKeysForSaveQuery
(
$this
->
newQuery
());
...
@@ -449,7 +423,9 @@ abstract class Model extends BaseModel {
...
@@ -449,7 +423,9 @@ abstract class Model extends BaseModel {
public
function
pull
(
$column
,
$values
)
public
function
pull
(
$column
,
$values
)
{
{
// Do batch pull by default.
// Do batch pull by default.
if
(
!
is_array
(
$values
))
$values
=
[
$values
];
if
(
!
is_array
(
$values
))
{
$values
=
[
$values
];
}
$query
=
$this
->
setKeysForSaveQuery
(
$this
->
newQuery
());
$query
=
$this
->
setKeysForSaveQuery
(
$this
->
newQuery
());
...
@@ -469,10 +445,11 @@ abstract class Model extends BaseModel {
...
@@ -469,10 +445,11 @@ abstract class Model extends BaseModel {
{
{
$current
=
$this
->
getAttributeFromArray
(
$column
)
?:
[];
$current
=
$this
->
getAttributeFromArray
(
$column
)
?:
[];
foreach
(
$values
as
$value
)
foreach
(
$values
as
$value
)
{
{
// Don't add duplicate values when we only want unique values.
// Don't add duplicate values when we only want unique values.
if
(
$unique
and
in_array
(
$value
,
$current
))
continue
;
if
(
$unique
and
in_array
(
$value
,
$current
))
{
continue
;
}
array_push
(
$current
,
$value
);
array_push
(
$current
,
$value
);
}
}
...
@@ -492,12 +469,10 @@ abstract class Model extends BaseModel {
...
@@ -492,12 +469,10 @@ abstract class Model extends BaseModel {
{
{
$current
=
$this
->
getAttributeFromArray
(
$column
)
?:
[];
$current
=
$this
->
getAttributeFromArray
(
$column
)
?:
[];
foreach
(
$values
as
$value
)
foreach
(
$values
as
$value
)
{
{
$keys
=
array_keys
(
$current
,
$value
);
$keys
=
array_keys
(
$current
,
$value
);
foreach
(
$keys
as
$key
)
foreach
(
$keys
as
$key
)
{
{
unset
(
$current
[
$key
]);
unset
(
$current
[
$key
]);
}
}
}
}
...
@@ -560,12 +535,10 @@ abstract class Model extends BaseModel {
...
@@ -560,12 +535,10 @@ abstract class Model extends BaseModel {
public
function
__call
(
$method
,
$parameters
)
public
function
__call
(
$method
,
$parameters
)
{
{
// Unset method
// Unset method
if
(
$method
==
'unset'
)
if
(
$method
==
'unset'
)
{
{
return
call_user_func_array
([
$this
,
'drop'
],
$parameters
);
return
call_user_func_array
([
$this
,
'drop'
],
$parameters
);
}
}
return
parent
::
__call
(
$method
,
$parameters
);
return
parent
::
__call
(
$method
,
$parameters
);
}
}
}
}
src/Jenssegers/Mongodb/Eloquent/SoftDeletes.php
View file @
76858f3c
<?php
namespace
Jenssegers\Mongodb\Eloquent
;
<?php
namespace
Jenssegers\Mongodb\Eloquent
;
trait
SoftDeletes
{
trait
SoftDeletes
{
use
\Illuminate\Database\Eloquent\SoftDeletes
;
use
\Illuminate\Database\Eloquent\SoftDeletes
;
...
@@ -13,5 +14,4 @@ trait SoftDeletes {
...
@@ -13,5 +14,4 @@ trait SoftDeletes {
{
{
return
$this
->
getDeletedAtColumn
();
return
$this
->
getDeletedAtColumn
();
}
}
}
}
src/Jenssegers/Mongodb/MongodbServiceProvider.php
View file @
76858f3c
...
@@ -3,7 +3,8 @@
...
@@ -3,7 +3,8 @@
use
Illuminate\Support\ServiceProvider
;
use
Illuminate\Support\ServiceProvider
;
use
Jenssegers\Mongodb\Eloquent\Model
;
use
Jenssegers\Mongodb\Eloquent\Model
;
class
MongodbServiceProvider
extends
ServiceProvider
{
class
MongodbServiceProvider
extends
ServiceProvider
{
/**
/**
* Bootstrap the application events.
* Bootstrap the application events.
...
@@ -20,13 +21,10 @@ class MongodbServiceProvider extends ServiceProvider {
...
@@ -20,13 +21,10 @@ class MongodbServiceProvider extends ServiceProvider {
*/
*/
public
function
register
()
public
function
register
()
{
{
$this
->
app
->
resolving
(
'db'
,
function
(
$db
)
$this
->
app
->
resolving
(
'db'
,
function
(
$db
)
{
{
$db
->
extend
(
'mongodb'
,
function
(
$config
)
{
$db
->
extend
(
'mongodb'
,
function
(
$config
)
{
return
new
Connection
(
$config
);
return
new
Connection
(
$config
);
});
});
});
});
}
}
}
}
src/Jenssegers/Mongodb/Query/Builder.php
View file @
76858f3c
...
@@ -11,7 +11,8 @@ use MongoDB\BSON\ObjectID;
...
@@ -11,7 +11,8 @@ use MongoDB\BSON\ObjectID;
use
MongoDB\BSON\Regex
;
use
MongoDB\BSON\Regex
;
use
MongoDB\BSON\UTCDateTime
;
use
MongoDB\BSON\UTCDateTime
;
class
Builder
extends
BaseBuilder
{
class
Builder
extends
BaseBuilder
{
/**
/**
* The database collection.
* The database collection.
...
@@ -163,24 +164,25 @@ class Builder extends BaseBuilder {
...
@@ -163,24 +164,25 @@ class Builder extends BaseBuilder {
// If no columns have been specified for the select statement, we will set them
// If no columns have been specified for the select statement, we will set them
// here to either the passed columns, or the standard default of retrieving
// here to either the passed columns, or the standard default of retrieving
// all of the columns on the table using the "wildcard" column character.
// all of the columns on the table using the "wildcard" column character.
if
(
is_null
(
$this
->
columns
))
$this
->
columns
=
$columns
;
if
(
is_null
(
$this
->
columns
))
{
$this
->
columns
=
$columns
;
}
// Drop all columns if * is present, MongoDB does not work this way.
// Drop all columns if * is present, MongoDB does not work this way.
if
(
in_array
(
'*'
,
$this
->
columns
))
$this
->
columns
=
[];
if
(
in_array
(
'*'
,
$this
->
columns
))
{
$this
->
columns
=
[];
}
// Compile wheres
// Compile wheres
$wheres
=
$this
->
compileWheres
();
$wheres
=
$this
->
compileWheres
();
// Use MongoDB's aggregation framework when using grouping or aggregation functions.
// Use MongoDB's aggregation framework when using grouping or aggregation functions.
if
(
$this
->
groups
or
$this
->
aggregate
or
$this
->
paginating
)
if
(
$this
->
groups
or
$this
->
aggregate
or
$this
->
paginating
)
{
{
$group
=
[];
$group
=
[];
// Add grouping columns to the $group part of the aggregation pipeline.
// Add grouping columns to the $group part of the aggregation pipeline.
if
(
$this
->
groups
)
if
(
$this
->
groups
)
{
{
foreach
(
$this
->
groups
as
$column
)
{
foreach
(
$this
->
groups
as
$column
)
{
$group
[
'_id'
][
$column
]
=
'$'
.
$column
;
$group
[
'_id'
][
$column
]
=
'$'
.
$column
;
// When grouping, also add the $last operator to each grouped field,
// When grouping, also add the $last operator to each grouped field,
...
@@ -189,8 +191,7 @@ class Builder extends BaseBuilder {
...
@@ -189,8 +191,7 @@ class Builder extends BaseBuilder {
}
}
// Do the same for other columns that are selected.
// Do the same for other columns that are selected.
foreach
(
$this
->
columns
as
$column
)
foreach
(
$this
->
columns
as
$column
)
{
{
$key
=
str_replace
(
'.'
,
'_'
,
$column
);
$key
=
str_replace
(
'.'
,
'_'
,
$column
);
$group
[
$key
]
=
[
'$last'
=>
'$'
.
$column
];
$group
[
$key
]
=
[
'$last'
=>
'$'
.
$column
];
...
@@ -199,20 +200,16 @@ class Builder extends BaseBuilder {
...
@@ -199,20 +200,16 @@ class Builder extends BaseBuilder {
// Add aggregation functions to the $group part of the aggregation pipeline,
// Add aggregation functions to the $group part of the aggregation pipeline,
// these may override previous aggregations.
// these may override previous aggregations.
if
(
$this
->
aggregate
)
if
(
$this
->
aggregate
)
{
{
$function
=
$this
->
aggregate
[
'function'
];
$function
=
$this
->
aggregate
[
'function'
];
foreach
(
$this
->
aggregate
[
'columns'
]
as
$column
)
foreach
(
$this
->
aggregate
[
'columns'
]
as
$column
)
{
{
// Translate count into sum.
// Translate count into sum.
if
(
$function
==
'count'
)
if
(
$function
==
'count'
)
{
{
$group
[
'aggregate'
]
=
[
'$sum'
=>
1
];
$group
[
'aggregate'
]
=
[
'$sum'
=>
1
];
}
}
// Pass other functions directly.
// Pass other functions directly.
else
else
{
{
$group
[
'aggregate'
]
=
[
'$'
.
$function
=>
'$'
.
$column
];
$group
[
'aggregate'
]
=
[
'$'
.
$function
=>
'$'
.
$column
];
}
}
}
}
...
@@ -220,30 +217,39 @@ class Builder extends BaseBuilder {
...
@@ -220,30 +217,39 @@ class Builder extends BaseBuilder {
// When using pagination, we limit the number of returned columns
// When using pagination, we limit the number of returned columns
// by adding a projection.
// by adding a projection.
if
(
$this
->
paginating
)
if
(
$this
->
paginating
)
{
{
foreach
(
$this
->
columns
as
$column
)
{
foreach
(
$this
->
columns
as
$column
)
{
$this
->
projections
[
$column
]
=
1
;
$this
->
projections
[
$column
]
=
1
;
}
}
}
}
// The _id field is mandatory when using grouping.
// The _id field is mandatory when using grouping.
if
(
$group
and
empty
(
$group
[
'_id'
]))
if
(
$group
and
empty
(
$group
[
'_id'
]))
{
{
$group
[
'_id'
]
=
null
;
$group
[
'_id'
]
=
null
;
}
}
// Build the aggregation pipeline.
// Build the aggregation pipeline.
$pipeline
=
[];
$pipeline
=
[];
if
(
$wheres
)
$pipeline
[]
=
[
'$match'
=>
$wheres
];
if
(
$wheres
)
{
if
(
$group
)
$pipeline
[]
=
[
'$group'
=>
$group
];
$pipeline
[]
=
[
'$match'
=>
$wheres
];
}
if
(
$group
)
{
$pipeline
[]
=
[
'$group'
=>
$group
];
}
// Apply order and limit
// Apply order and limit
if
(
$this
->
orders
)
$pipeline
[]
=
[
'$sort'
=>
$this
->
orders
];
if
(
$this
->
orders
)
{
if
(
$this
->
offset
)
$pipeline
[]
=
[
'$skip'
=>
$this
->
offset
];
$pipeline
[]
=
[
'$sort'
=>
$this
->
orders
];
if
(
$this
->
limit
)
$pipeline
[]
=
[
'$limit'
=>
$this
->
limit
];
}
if
(
$this
->
projections
)
$pipeline
[]
=
[
'$project'
=>
$this
->
projections
];
if
(
$this
->
offset
)
{
$pipeline
[]
=
[
'$skip'
=>
$this
->
offset
];
}
if
(
$this
->
limit
)
{
$pipeline
[]
=
[
'$limit'
=>
$this
->
limit
];
}
if
(
$this
->
projections
)
{
$pipeline
[]
=
[
'$project'
=>
$this
->
projections
];
}
$options
=
[
$options
=
[
'typeMap'
=>
[
'root'
=>
'array'
,
'document'
=>
'array'
],
'typeMap'
=>
[
'root'
=>
'array'
,
'document'
=>
'array'
],
...
@@ -257,18 +263,14 @@ class Builder extends BaseBuilder {
...
@@ -257,18 +263,14 @@ class Builder extends BaseBuilder {
}
}
// Distinct query
// Distinct query
elseif
(
$this
->
distinct
)
elseif
(
$this
->
distinct
)
{
{
// Return distinct results directly
// Return distinct results directly
$column
=
isset
(
$this
->
columns
[
0
])
?
$this
->
columns
[
0
]
:
'_id'
;
$column
=
isset
(
$this
->
columns
[
0
])
?
$this
->
columns
[
0
]
:
'_id'
;
// Execute distinct
// Execute distinct
if
(
$wheres
)
if
(
$wheres
)
{
{
$result
=
$this
->
collection
->
distinct
(
$column
,
$wheres
);
$result
=
$this
->
collection
->
distinct
(
$column
,
$wheres
);
}
}
else
{
else
{
$result
=
$this
->
collection
->
distinct
(
$column
);
$result
=
$this
->
collection
->
distinct
(
$column
);
}
}
...
@@ -276,29 +278,36 @@ class Builder extends BaseBuilder {
...
@@ -276,29 +278,36 @@ class Builder extends BaseBuilder {
}
}
// Normal query
// Normal query
else
else
{
{
$columns
=
[];
$columns
=
[];
// Convert select columns to simple projections.
// Convert select columns to simple projections.
foreach
(
$this
->
columns
as
$column
)
foreach
(
$this
->
columns
as
$column
)
{
{
$columns
[
$column
]
=
true
;
$columns
[
$column
]
=
true
;
}
}
// Add custom projections.
// Add custom projections.
if
(
$this
->
projections
)
if
(
$this
->
projections
)
{
{
$columns
=
array_merge
(
$columns
,
$this
->
projections
);
$columns
=
array_merge
(
$columns
,
$this
->
projections
);
}
}
$options
=
[];
$options
=
[];
// Apply order, offset, limit and projection
// Apply order, offset, limit and projection
if
(
$this
->
timeout
)
$options
[
'maxTimeMS'
]
=
$this
->
timeout
;
if
(
$this
->
timeout
)
{
if
(
$this
->
orders
)
$options
[
'sort'
]
=
$this
->
orders
;
$options
[
'maxTimeMS'
]
=
$this
->
timeout
;
if
(
$this
->
offset
)
$options
[
'skip'
]
=
$this
->
offset
;
}
if
(
$this
->
limit
)
$options
[
'limit'
]
=
$this
->
limit
;
if
(
$this
->
orders
)
{
if
(
$columns
)
$options
[
'projection'
]
=
$columns
;
$options
[
'sort'
]
=
$this
->
orders
;
}
if
(
$this
->
offset
)
{
$options
[
'skip'
]
=
$this
->
offset
;
}
if
(
$this
->
limit
)
{
$options
[
'limit'
]
=
$this
->
limit
;
}
if
(
$columns
)
{
$options
[
'projection'
]
=
$columns
;
}
// if ($this->hint) $cursor->hint($this->hint);
// if ($this->hint) $cursor->hint($this->hint);
// Fix for legacy support, converts the results to arrays instead of objects.
// Fix for legacy support, converts the results to arrays instead of objects.
...
@@ -350,10 +359,10 @@ class Builder extends BaseBuilder {
...
@@ -350,10 +359,10 @@ class Builder extends BaseBuilder {
// Once we have executed the query, we will reset the aggregate property so
// Once we have executed the query, we will reset the aggregate property so
// that more select queries can be executed against the database without
// that more select queries can be executed against the database without
// the aggregate value getting in the way when the grammar builds it.
// the aggregate value getting in the way when the grammar builds it.
$this
->
columns
=
null
;
$this
->
aggregate
=
null
;
$this
->
columns
=
null
;
$this
->
aggregate
=
null
;
if
(
isset
(
$results
[
0
]))
if
(
isset
(
$results
[
0
]))
{
{
$result
=
(
array
)
$results
[
0
];
$result
=
(
array
)
$results
[
0
];
return
$result
[
'aggregate'
];
return
$result
[
'aggregate'
];
...
@@ -379,8 +388,7 @@ class Builder extends BaseBuilder {
...
@@ -379,8 +388,7 @@ class Builder extends BaseBuilder {
{
{
$this
->
distinct
=
true
;
$this
->
distinct
=
true
;
if
(
$column
)
if
(
$column
)
{
{
$this
->
columns
=
[
$column
];
$this
->
columns
=
[
$column
];
}
}
...
@@ -396,17 +404,13 @@ class Builder extends BaseBuilder {
...
@@ -396,17 +404,13 @@ class Builder extends BaseBuilder {
*/
*/
public
function
orderBy
(
$column
,
$direction
=
'asc'
)
public
function
orderBy
(
$column
,
$direction
=
'asc'
)
{
{
if
(
is_string
(
$direction
))
if
(
is_string
(
$direction
))
{
{
$direction
=
(
strtolower
(
$direction
)
==
'asc'
?
1
:
-
1
);
$direction
=
(
strtolower
(
$direction
)
==
'asc'
?
1
:
-
1
);
}
}
if
(
$column
==
'natural'
)
if
(
$column
==
'natural'
)
{
{
$this
->
orders
[
'$natural'
]
=
$direction
;
$this
->
orders
[
'$natural'
]
=
$direction
;
}
}
else
{
else
{
$this
->
orders
[
$column
]
=
$direction
;
$this
->
orders
[
$column
]
=
$direction
;
}
}
...
@@ -457,17 +461,18 @@ class Builder extends BaseBuilder {
...
@@ -457,17 +461,18 @@ class Builder extends BaseBuilder {
// if the user is inserting a single document or an array of documents.
// if the user is inserting a single document or an array of documents.
$batch
=
true
;
$batch
=
true
;
foreach
(
$values
as
$value
)
foreach
(
$values
as
$value
)
{
{
// As soon as we find a value that is not an array we assume the user is
// As soon as we find a value that is not an array we assume the user is
// inserting a single document.
// inserting a single document.
if
(
!
is_array
(
$value
))
if
(
!
is_array
(
$value
))
{
{
$batch
=
false
;
$batch
=
false
;
break
;
break
;
}
}
}
}
if
(
!
$batch
)
$values
=
[
$values
];
if
(
!
$batch
)
{
$values
=
[
$values
];
}
// Batch insert
// Batch insert
$result
=
$this
->
collection
->
insertMany
(
$values
);
$result
=
$this
->
collection
->
insertMany
(
$values
);
...
@@ -486,10 +491,8 @@ class Builder extends BaseBuilder {
...
@@ -486,10 +491,8 @@ class Builder extends BaseBuilder {
{
{
$result
=
$this
->
collection
->
insertOne
(
$values
);
$result
=
$this
->
collection
->
insertOne
(
$values
);
if
(
1
==
(
int
)
$result
->
isAcknowledged
())
if
(
1
==
(
int
)
$result
->
isAcknowledged
())
{
{
if
(
is_null
(
$sequence
))
{
if
(
is_null
(
$sequence
))
{
$sequence
=
'_id'
;
$sequence
=
'_id'
;
}
}
...
@@ -508,8 +511,7 @@ class Builder extends BaseBuilder {
...
@@ -508,8 +511,7 @@ class Builder extends BaseBuilder {
public
function
update
(
array
$values
,
array
$options
=
[])
public
function
update
(
array
$values
,
array
$options
=
[])
{
{
// Use $set as default operator.
// Use $set as default operator.
if
(
!
starts_with
(
key
(
$values
),
'$'
))
if
(
!
starts_with
(
key
(
$values
),
'$'
))
{
{
$values
=
[
'$set'
=>
$values
];
$values
=
[
'$set'
=>
$values
];
}
}
...
@@ -528,14 +530,12 @@ class Builder extends BaseBuilder {
...
@@ -528,14 +530,12 @@ class Builder extends BaseBuilder {
{
{
$query
=
[
'$inc'
=>
[
$column
=>
$amount
]];
$query
=
[
'$inc'
=>
[
$column
=>
$amount
]];
if
(
!
empty
(
$extra
))
if
(
!
empty
(
$extra
))
{
{
$query
[
'$set'
]
=
$extra
;
$query
[
'$set'
]
=
$extra
;
}
}
// Protect
// Protect
$this
->
where
(
function
(
$query
)
use
(
$column
)
$this
->
where
(
function
(
$query
)
use
(
$column
)
{
{
$query
->
where
(
$column
,
'exists'
,
false
);
$query
->
where
(
$column
,
'exists'
,
false
);
$query
->
orWhereNotNull
(
$column
);
$query
->
orWhereNotNull
(
$column
);
...
@@ -588,8 +588,7 @@ class Builder extends BaseBuilder {
...
@@ -588,8 +588,7 @@ class Builder extends BaseBuilder {
{
{
$wheres
=
$this
->
compileWheres
();
$wheres
=
$this
->
compileWheres
();
$result
=
$this
->
collection
->
DeleteMany
(
$wheres
);
$result
=
$this
->
collection
->
DeleteMany
(
$wheres
);
if
(
1
==
(
int
)
$result
->
isAcknowledged
())
if
(
1
==
(
int
)
$result
->
isAcknowledged
())
{
{
return
$result
->
getDeletedCount
();
return
$result
->
getDeletedCount
();
}
}
...
@@ -604,8 +603,7 @@ class Builder extends BaseBuilder {
...
@@ -604,8 +603,7 @@ class Builder extends BaseBuilder {
*/
*/
public
function
from
(
$collection
)
public
function
from
(
$collection
)
{
{
if
(
$collection
)
if
(
$collection
)
{
{
$this
->
collection
=
$this
->
connection
->
getCollection
(
$collection
);
$this
->
collection
=
$this
->
connection
->
getCollection
(
$collection
);
}
}
...
@@ -631,13 +629,11 @@ class Builder extends BaseBuilder {
...
@@ -631,13 +629,11 @@ class Builder extends BaseBuilder {
*/
*/
public
function
lists
(
$column
,
$key
=
null
)
public
function
lists
(
$column
,
$key
=
null
)
{
{
if
(
$key
==
'_id'
)
if
(
$key
==
'_id'
)
{
{
$results
=
new
Collection
(
$this
->
get
([
$column
,
$key
]));
$results
=
new
Collection
(
$this
->
get
([
$column
,
$key
]));
// Convert ObjectID's to strings so that lists can do its work.
// Convert ObjectID's to strings so that lists can do its work.
$results
=
$results
->
map
(
function
(
$item
)
$results
=
$results
->
map
(
function
(
$item
)
{
{
$item
[
'_id'
]
=
(
string
)
$item
[
'_id'
];
$item
[
'_id'
]
=
(
string
)
$item
[
'_id'
];
return
$item
;
return
$item
;
...
@@ -658,14 +654,12 @@ class Builder extends BaseBuilder {
...
@@ -658,14 +654,12 @@ class Builder extends BaseBuilder {
public
function
raw
(
$expression
=
null
)
public
function
raw
(
$expression
=
null
)
{
{
// Execute the closure on the mongodb collection
// Execute the closure on the mongodb collection
if
(
$expression
instanceof
Closure
)
if
(
$expression
instanceof
Closure
)
{
{
return
call_user_func
(
$expression
,
$this
->
collection
);
return
call_user_func
(
$expression
,
$this
->
collection
);
}
}
// Create an expression for the given value
// Create an expression for the given value
elseif
(
!
is_null
(
$expression
))
elseif
(
!
is_null
(
$expression
))
{
{
return
new
Expression
(
$expression
);
return
new
Expression
(
$expression
);
}
}
...
@@ -688,16 +682,11 @@ class Builder extends BaseBuilder {
...
@@ -688,16 +682,11 @@ class Builder extends BaseBuilder {
// Check if we are pushing multiple values.
// Check if we are pushing multiple values.
$batch
=
(
is_array
(
$value
)
and
array_keys
(
$value
)
===
range
(
0
,
count
(
$value
)
-
1
));
$batch
=
(
is_array
(
$value
)
and
array_keys
(
$value
)
===
range
(
0
,
count
(
$value
)
-
1
));
if
(
is_array
(
$column
))
if
(
is_array
(
$column
))
{
{
$query
=
[
$operator
=>
$column
];
$query
=
[
$operator
=>
$column
];
}
}
elseif
(
$batch
)
{
elseif
(
$batch
)
{
$query
=
[
$operator
=>
[
$column
=>
[
'$each'
=>
$value
]]];
$query
=
[
$operator
=>
[
$column
=>
[
'$each'
=>
$value
]]];
}
}
else
{
else
{
$query
=
[
$operator
=>
[
$column
=>
$value
]];
$query
=
[
$operator
=>
[
$column
=>
$value
]];
}
}
...
@@ -719,12 +708,9 @@ class Builder extends BaseBuilder {
...
@@ -719,12 +708,9 @@ class Builder extends BaseBuilder {
// If we are pulling multiple values, we need to use $pullAll.
// If we are pulling multiple values, we need to use $pullAll.
$operator
=
$batch
?
'$pullAll'
:
'$pull'
;
$operator
=
$batch
?
'$pullAll'
:
'$pull'
;
if
(
is_array
(
$column
))
if
(
is_array
(
$column
))
{
{
$query
=
[
$operator
=>
$column
];
$query
=
[
$operator
=>
$column
];
}
}
else
{
else
{
$query
=
[
$operator
=>
[
$column
=>
$value
]];
$query
=
[
$operator
=>
[
$column
=>
$value
]];
}
}
...
@@ -739,12 +725,13 @@ class Builder extends BaseBuilder {
...
@@ -739,12 +725,13 @@ class Builder extends BaseBuilder {
*/
*/
public
function
drop
(
$columns
)
public
function
drop
(
$columns
)
{
{
if
(
!
is_array
(
$columns
))
$columns
=
[
$columns
];
if
(
!
is_array
(
$columns
))
{
$columns
=
[
$columns
];
}
$fields
=
[];
$fields
=
[];
foreach
(
$columns
as
$column
)
foreach
(
$columns
as
$column
)
{
{
$fields
[
$column
]
=
1
;
$fields
[
$column
]
=
1
;
}
}
...
@@ -773,15 +760,13 @@ class Builder extends BaseBuilder {
...
@@ -773,15 +760,13 @@ class Builder extends BaseBuilder {
protected
function
performUpdate
(
$query
,
array
$options
=
[])
protected
function
performUpdate
(
$query
,
array
$options
=
[])
{
{
// Update multiple items by default.
// Update multiple items by default.
if
(
!
array_key_exists
(
'multiple'
,
$options
))
if
(
!
array_key_exists
(
'multiple'
,
$options
))
{
{
$options
[
'multiple'
]
=
true
;
$options
[
'multiple'
]
=
true
;
}
}
$wheres
=
$this
->
compileWheres
();
$wheres
=
$this
->
compileWheres
();
$result
=
$this
->
collection
->
UpdateMany
(
$wheres
,
$query
,
$options
);
$result
=
$this
->
collection
->
UpdateMany
(
$wheres
,
$query
,
$options
);
if
(
1
==
(
int
)
$result
->
isAcknowledged
())
if
(
1
==
(
int
)
$result
->
isAcknowledged
())
{
{
return
$result
->
getModifiedCount
()
?
$result
->
getModifiedCount
()
:
$result
->
getUpsertedCount
();
return
$result
->
getModifiedCount
()
?
$result
->
getModifiedCount
()
:
$result
->
getUpsertedCount
();
}
}
...
@@ -796,8 +781,7 @@ class Builder extends BaseBuilder {
...
@@ -796,8 +781,7 @@ class Builder extends BaseBuilder {
*/
*/
public
function
convertKey
(
$id
)
public
function
convertKey
(
$id
)
{
{
if
(
is_string
(
$id
)
and
strlen
(
$id
)
===
24
and
ctype_xdigit
(
$id
))
if
(
is_string
(
$id
)
and
strlen
(
$id
)
===
24
and
ctype_xdigit
(
$id
))
{
{
return
new
ObjectID
(
$id
);
return
new
ObjectID
(
$id
);
}
}
...
@@ -820,12 +804,10 @@ class Builder extends BaseBuilder {
...
@@ -820,12 +804,10 @@ class Builder extends BaseBuilder {
$params
=
func_get_args
();
$params
=
func_get_args
();
// Remove the leading $ from operators.
// Remove the leading $ from operators.
if
(
func_num_args
()
==
3
)
if
(
func_num_args
()
==
3
)
{
{
$operator
=
&
$params
[
1
];
$operator
=
&
$params
[
1
];
if
(
starts_with
(
$operator
,
'$'
))
if
(
starts_with
(
$operator
,
'$'
))
{
{
$operator
=
substr
(
$operator
,
1
);
$operator
=
substr
(
$operator
,
1
);
}
}
}
}
...
@@ -846,11 +828,9 @@ class Builder extends BaseBuilder {
...
@@ -846,11 +828,9 @@ class Builder extends BaseBuilder {
// We will add all compiled wheres to this array.
// We will add all compiled wheres to this array.
$compiled
=
[];
$compiled
=
[];
foreach
(
$wheres
as
$i
=>
&
$where
)
foreach
(
$wheres
as
$i
=>
&
$where
)
{
{
// Make sure the operator is in lowercase.
// Make sure the operator is in lowercase.
if
(
isset
(
$where
[
'operator'
]))
if
(
isset
(
$where
[
'operator'
]))
{
{
$where
[
'operator'
]
=
strtolower
(
$where
[
'operator'
]);
$where
[
'operator'
]
=
strtolower
(
$where
[
'operator'
]);
// Operator conversions
// Operator conversions
...
@@ -865,42 +845,35 @@ class Builder extends BaseBuilder {
...
@@ -865,42 +845,35 @@ class Builder extends BaseBuilder {
'uniquedocs'
=>
'uniqueDocs'
,
'uniquedocs'
=>
'uniqueDocs'
,
];
];
if
(
array_key_exists
(
$where
[
'operator'
],
$convert
))
if
(
array_key_exists
(
$where
[
'operator'
],
$convert
))
{
{
$where
[
'operator'
]
=
$convert
[
$where
[
'operator'
]];
$where
[
'operator'
]
=
$convert
[
$where
[
'operator'
]];
}
}
}
}
// Convert id's.
// Convert id's.
if
(
isset
(
$where
[
'column'
])
and
(
$where
[
'column'
]
==
'_id'
or
ends_with
(
$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'
]))
{
{
foreach
(
$where
[
'values'
]
as
&
$value
)
{
foreach
(
$where
[
'values'
]
as
&
$value
)
{
$value
=
$this
->
convertKey
(
$value
);
$value
=
$this
->
convertKey
(
$value
);
}
}
}
}
// Single value.
// Single value.
elseif
(
isset
(
$where
[
'value'
]))
elseif
(
isset
(
$where
[
'value'
]))
{
{
$where
[
'value'
]
=
$this
->
convertKey
(
$where
[
'value'
]);
$where
[
'value'
]
=
$this
->
convertKey
(
$where
[
'value'
]);
}
}
}
}
// Convert DateTime values to UTCDateTime.
// Convert DateTime values to UTCDateTime.
if
(
isset
(
$where
[
'value'
])
and
$where
[
'value'
]
instanceof
DateTime
)
if
(
isset
(
$where
[
'value'
])
and
$where
[
'value'
]
instanceof
DateTime
)
{
{
$where
[
'value'
]
=
new
UTCDateTime
(
$where
[
'value'
]
->
getTimestamp
()
*
1000
);
$where
[
'value'
]
=
new
UTCDateTime
(
$where
[
'value'
]
->
getTimestamp
()
*
1000
);
}
}
// The next item in a "chain" of wheres devices the boolean of the
// The next item in a "chain" of wheres devices the boolean of the
// first item. So if we see that there are multiple wheres, we will
// first item. So if we see that there are multiple wheres, we will
// use the operator of the next where.
// use the operator of the next where.
if
(
$i
==
0
and
count
(
$wheres
)
>
1
and
$where
[
'boolean'
]
==
'and'
)
if
(
$i
==
0
and
count
(
$wheres
)
>
1
and
$where
[
'boolean'
]
==
'and'
)
{
{
$where
[
'boolean'
]
=
$wheres
[
$i
+
1
][
'boolean'
];
$where
[
'boolean'
]
=
$wheres
[
$i
+
1
][
'boolean'
];
}
}
...
@@ -909,15 +882,13 @@ class Builder extends BaseBuilder {
...
@@ -909,15 +882,13 @@ class Builder extends BaseBuilder {
$result
=
$this
->
{
$method
}(
$where
);
$result
=
$this
->
{
$method
}(
$where
);
// Wrap the where with an $or operator.
// Wrap the where with an $or operator.
if
(
$where
[
'boolean'
]
==
'or'
)
if
(
$where
[
'boolean'
]
==
'or'
)
{
{
$result
=
[
'$or'
=>
[
$result
]];
$result
=
[
'$or'
=>
[
$result
]];
}
}
// If there are multiple wheres, we will wrap it with $and. This is needed
// If there are multiple wheres, we will wrap it with $and. This is needed
// to make nested wheres work.
// to make nested wheres work.
elseif
(
count
(
$wheres
)
>
1
)
elseif
(
count
(
$wheres
)
>
1
)
{
{
$result
=
[
'$and'
=>
[
$result
]];
$result
=
[
'$and'
=>
[
$result
]];
}
}
...
@@ -933,24 +904,25 @@ class Builder extends BaseBuilder {
...
@@ -933,24 +904,25 @@ class Builder extends BaseBuilder {
extract
(
$where
);
extract
(
$where
);
// Replace like with a Regex instance.
// Replace like with a Regex instance.
if
(
$operator
==
'like'
)
if
(
$operator
==
'like'
)
{
{
$operator
=
'='
;
$operator
=
'='
;
$regex
=
str_replace
(
'%'
,
''
,
$value
);
$regex
=
str_replace
(
'%'
,
''
,
$value
);
// Convert like to regular expression.
// Convert like to regular expression.
if
(
!
starts_with
(
$value
,
'%'
))
$regex
=
'^'
.
$regex
;
if
(
!
starts_with
(
$value
,
'%'
))
{
if
(
!
ends_with
(
$value
,
'%'
))
$regex
=
$regex
.
'$'
;
$regex
=
'^'
.
$regex
;
}
if
(
!
ends_with
(
$value
,
'%'
))
{
$regex
=
$regex
.
'$'
;
}
$value
=
new
Regex
(
$regex
,
'i'
);
$value
=
new
Regex
(
$regex
,
'i'
);
}
}
// Manipulate regexp operations.
// Manipulate regexp operations.
elseif
(
in_array
(
$operator
,
[
'regexp'
,
'not regexp'
,
'regex'
,
'not regex'
]))
elseif
(
in_array
(
$operator
,
[
'regexp'
,
'not regexp'
,
'regex'
,
'not regex'
]))
{
{
// Automatically convert regular expression strings to Regex objects.
// Automatically convert regular expression strings to Regex objects.
if
(
!
$value
instanceof
Regex
)
if
(
!
$value
instanceof
Regex
)
{
{
$e
=
explode
(
'/'
,
$value
);
$e
=
explode
(
'/'
,
$value
);
$flag
=
end
(
$e
);
$flag
=
end
(
$e
);
$regstr
=
substr
(
$value
,
1
,
-
(
strlen
(
$flag
)
+
1
));
$regstr
=
substr
(
$value
,
1
,
-
(
strlen
(
$flag
)
+
1
));
...
@@ -959,22 +931,16 @@ class Builder extends BaseBuilder {
...
@@ -959,22 +931,16 @@ class Builder extends BaseBuilder {
// For inverse regexp operations, we can just use the $not operator
// For inverse regexp operations, we can just use the $not operator
// and pass it a Regex instence.
// and pass it a Regex instence.
if
(
starts_with
(
$operator
,
'not'
))
if
(
starts_with
(
$operator
,
'not'
))
{
{
$operator
=
'not'
;
$operator
=
'not'
;
}
}
}
}
if
(
!
isset
(
$operator
)
or
$operator
==
'='
)
if
(
!
isset
(
$operator
)
or
$operator
==
'='
)
{
{
$query
=
[
$column
=>
$value
];
$query
=
[
$column
=>
$value
];
}
}
elseif
(
array_key_exists
(
$operator
,
$this
->
conversion
))
{
elseif
(
array_key_exists
(
$operator
,
$this
->
conversion
))
{
$query
=
[
$column
=>
[
$this
->
conversion
[
$operator
]
=>
$value
]];
$query
=
[
$column
=>
[
$this
->
conversion
[
$operator
]
=>
$value
]];
}
}
else
{
else
{
$query
=
[
$column
=>
[
'$'
.
$operator
=>
$value
]];
$query
=
[
$column
=>
[
'$'
.
$operator
=>
$value
]];
}
}
...
@@ -1022,8 +988,7 @@ class Builder extends BaseBuilder {
...
@@ -1022,8 +988,7 @@ class Builder extends BaseBuilder {
{
{
extract
(
$where
);
extract
(
$where
);
if
(
$not
)
if
(
$not
)
{
{
return
[
return
[
'$or'
=>
[
'$or'
=>
[
[
[
...
@@ -1038,9 +1003,7 @@ class Builder extends BaseBuilder {
...
@@ -1038,9 +1003,7 @@ class Builder extends BaseBuilder {
],
],
],
],
];
];
}
}
else
{
else
{
return
[
return
[
$column
=>
[
$column
=>
[
'$gte'
=>
$values
[
0
],
'$gte'
=>
$values
[
0
],
...
@@ -1064,12 +1027,10 @@ class Builder extends BaseBuilder {
...
@@ -1064,12 +1027,10 @@ class Builder extends BaseBuilder {
*/
*/
public
function
__call
(
$method
,
$parameters
)
public
function
__call
(
$method
,
$parameters
)
{
{
if
(
$method
==
'unset'
)
if
(
$method
==
'unset'
)
{
{
return
call_user_func_array
([
$this
,
'drop'
],
$parameters
);
return
call_user_func_array
([
$this
,
'drop'
],
$parameters
);
}
}
return
parent
::
__call
(
$method
,
$parameters
);
return
parent
::
__call
(
$method
,
$parameters
);
}
}
}
}
src/Jenssegers/Mongodb/Query/Grammar.php
View file @
76858f3c
...
@@ -2,6 +2,6 @@
...
@@ -2,6 +2,6 @@
use
Illuminate\Database\Query\Grammars\Grammar
as
BaseGrammar
;
use
Illuminate\Database\Query\Grammars\Grammar
as
BaseGrammar
;
class
Grammar
extends
BaseGrammar
{
class
Grammar
extends
BaseGrammar
{
}
}
src/Jenssegers/Mongodb/Query/Processor.php
View file @
76858f3c
...
@@ -2,6 +2,6 @@
...
@@ -2,6 +2,6 @@
use
Illuminate\Database\Query\Processors\Processor
as
BaseProcessor
;
use
Illuminate\Database\Query\Processors\Processor
as
BaseProcessor
;
class
Processor
extends
BaseProcessor
{
class
Processor
extends
BaseProcessor
{
}
}
src/Jenssegers/Mongodb/Relations/BelongsTo.php
View file @
76858f3c
<?php
namespace
Jenssegers\Mongodb\Relations
;
<?php
namespace
Jenssegers\Mongodb\Relations
;
class
BelongsTo
extends
\Illuminate\Database\Eloquent\Relations\BelongsTo
{
class
BelongsTo
extends
\Illuminate\Database\Eloquent\Relations\BelongsTo
{
/**
/**
* Set the base constraints on the relation query.
* Set the base constraints on the relation query.
*/
*/
public
function
addConstraints
()
public
function
addConstraints
()
{
{
if
(
static
::
$constraints
)
if
(
static
::
$constraints
)
{
{
// For belongs to relationships, which are essentially the inverse of has one
// For belongs to relationships, which are essentially the inverse of has one
// or has many relationships, we need to actually query on the primary key
// or has many relationships, we need to actually query on the primary key
// of the related models matching on the foreign key that's on a parent.
// of the related models matching on the foreign key that's on a parent.
...
@@ -30,5 +30,4 @@ class BelongsTo extends \Illuminate\Database\Eloquent\Relations\BelongsTo {
...
@@ -30,5 +30,4 @@ class BelongsTo extends \Illuminate\Database\Eloquent\Relations\BelongsTo {
$this
->
query
->
whereIn
(
$key
,
$this
->
getEagerModelKeys
(
$models
));
$this
->
query
->
whereIn
(
$key
,
$this
->
getEagerModelKeys
(
$models
));
}
}
}
}
src/Jenssegers/Mongodb/Relations/BelongsToMany.php
View file @
76858f3c
...
@@ -4,7 +4,8 @@ use Illuminate\Database\Eloquent\Collection;
...
@@ -4,7 +4,8 @@ use Illuminate\Database\Eloquent\Collection;
use
Illuminate\Database\Eloquent\Model
;
use
Illuminate\Database\Eloquent\Model
;
use
Illuminate\Database\Eloquent\Relations\BelongsToMany
as
EloquentBelongsToMany
;
use
Illuminate\Database\Eloquent\Relations\BelongsToMany
as
EloquentBelongsToMany
;
class
BelongsToMany
extends
EloquentBelongsToMany
{
class
BelongsToMany
extends
EloquentBelongsToMany
{
/**
/**
* Hydrate the pivot table relationship on the models.
* Hydrate the pivot table relationship on the models.
...
@@ -32,7 +33,9 @@ class BelongsToMany extends EloquentBelongsToMany {
...
@@ -32,7 +33,9 @@ class BelongsToMany extends EloquentBelongsToMany {
*/
*/
public
function
addConstraints
()
public
function
addConstraints
()
{
{
if
(
static
::
$constraints
)
$this
->
setWhere
();
if
(
static
::
$constraints
)
{
$this
->
setWhere
();
}
}
}
/**
/**
...
@@ -101,7 +104,9 @@ class BelongsToMany extends EloquentBelongsToMany {
...
@@ -101,7 +104,9 @@ class BelongsToMany extends EloquentBelongsToMany {
'attached'
=>
[],
'detached'
=>
[],
'updated'
=>
[],
'attached'
=>
[],
'detached'
=>
[],
'updated'
=>
[],
];
];
if
(
$ids
instanceof
Collection
)
$ids
=
$ids
->
modelKeys
();
if
(
$ids
instanceof
Collection
)
{
$ids
=
$ids
->
modelKeys
();
}
// First we need to attach any of the associated models that are not currently
// First we need to attach any of the associated models that are not currently
// in this joining table. We'll spin through the given IDs, checking to see
// in this joining table. We'll spin through the given IDs, checking to see
...
@@ -109,7 +114,9 @@ class BelongsToMany extends EloquentBelongsToMany {
...
@@ -109,7 +114,9 @@ class BelongsToMany extends EloquentBelongsToMany {
$current
=
$this
->
parent
->
{
$this
->
otherKey
}
?:
[];
$current
=
$this
->
parent
->
{
$this
->
otherKey
}
?:
[];
// See issue #256.
// See issue #256.
if
(
$current
instanceof
Collection
)
$current
=
$ids
->
modelKeys
();
if
(
$current
instanceof
Collection
)
{
$current
=
$ids
->
modelKeys
();
}
$records
=
$this
->
formatSyncList
(
$ids
);
$records
=
$this
->
formatSyncList
(
$ids
);
...
@@ -122,12 +129,10 @@ class BelongsToMany extends EloquentBelongsToMany {
...
@@ -122,12 +129,10 @@ class BelongsToMany extends EloquentBelongsToMany {
// 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
// the array of the IDs given to the method which will complete the sync.
// the array of the IDs given to the method which will complete the sync.
if
(
$detaching
and
count
(
$detach
)
>
0
)
if
(
$detaching
and
count
(
$detach
)
>
0
)
{
{
$this
->
detach
(
$detach
);
$this
->
detach
(
$detach
);
$changes
[
'detached'
]
=
(
array
)
array_map
(
function
(
$v
)
$changes
[
'detached'
]
=
(
array
)
array_map
(
function
(
$v
)
{
{
return
is_numeric
(
$v
)
?
(
int
)
$v
:
(
string
)
$v
;
return
is_numeric
(
$v
)
?
(
int
)
$v
:
(
string
)
$v
;
},
$detach
);
},
$detach
);
}
}
...
@@ -139,8 +144,7 @@ class BelongsToMany extends EloquentBelongsToMany {
...
@@ -139,8 +144,7 @@ class BelongsToMany extends EloquentBelongsToMany {
$changes
,
$this
->
attachNew
(
$records
,
$current
,
false
)
$changes
,
$this
->
attachNew
(
$records
,
$current
,
false
)
);
);
if
(
count
(
$changes
[
'attached'
])
||
count
(
$changes
[
'updated'
]))
if
(
count
(
$changes
[
'attached'
])
||
count
(
$changes
[
'updated'
]))
{
{
$this
->
touchIfTouching
();
$this
->
touchIfTouching
();
}
}
...
@@ -168,17 +172,14 @@ class BelongsToMany extends EloquentBelongsToMany {
...
@@ -168,17 +172,14 @@ class BelongsToMany extends EloquentBelongsToMany {
*/
*/
public
function
attach
(
$id
,
array
$attributes
=
[],
$touch
=
true
)
public
function
attach
(
$id
,
array
$attributes
=
[],
$touch
=
true
)
{
{
if
(
$id
instanceof
Model
)
if
(
$id
instanceof
Model
)
{
{
$model
=
$id
;
$model
=
$id
;
$id
=
$model
->
getKey
();
$id
=
$model
->
getKey
();
// Attach the new parent id to the related model.
// Attach the new parent id 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
();
$query
->
whereIn
(
$this
->
related
->
getKeyName
(),
(
array
)
$id
);
$query
->
whereIn
(
$this
->
related
->
getKeyName
(),
(
array
)
$id
);
...
@@ -190,7 +191,9 @@ class BelongsToMany extends EloquentBelongsToMany {
...
@@ -190,7 +191,9 @@ class BelongsToMany extends EloquentBelongsToMany {
// Attach the new ids to the parent model.
// Attach the new ids to the parent model.
$this
->
parent
->
push
(
$this
->
otherKey
,
(
array
)
$id
,
true
);
$this
->
parent
->
push
(
$this
->
otherKey
,
(
array
)
$id
,
true
);
if
(
$touch
)
$this
->
touchIfTouching
();
if
(
$touch
)
{
$this
->
touchIfTouching
();
}
}
}
/**
/**
...
@@ -202,7 +205,9 @@ class BelongsToMany extends EloquentBelongsToMany {
...
@@ -202,7 +205,9 @@ class BelongsToMany extends EloquentBelongsToMany {
*/
*/
public
function
detach
(
$ids
=
[],
$touch
=
true
)
public
function
detach
(
$ids
=
[],
$touch
=
true
)
{
{
if
(
$ids
instanceof
Model
)
$ids
=
(
array
)
$ids
->
getKey
();
if
(
$ids
instanceof
Model
)
{
$ids
=
(
array
)
$ids
->
getKey
();
}
$query
=
$this
->
newRelatedQuery
();
$query
=
$this
->
newRelatedQuery
();
...
@@ -215,15 +220,16 @@ class BelongsToMany extends EloquentBelongsToMany {
...
@@ -215,15 +220,16 @@ class BelongsToMany extends EloquentBelongsToMany {
$this
->
parent
->
pull
(
$this
->
otherKey
,
$ids
);
$this
->
parent
->
pull
(
$this
->
otherKey
,
$ids
);
// Prepare the query to select all related objects.
// Prepare the query to select all related objects.
if
(
count
(
$ids
)
>
0
)
if
(
count
(
$ids
)
>
0
)
{
{
$query
->
whereIn
(
$this
->
related
->
getKeyName
(),
$ids
);
$query
->
whereIn
(
$this
->
related
->
getKeyName
(),
$ids
);
}
}
// Remove the relation to the parent.
// Remove the relation to the parent.
$query
->
pull
(
$this
->
foreignKey
,
$this
->
parent
->
getKey
());
$query
->
pull
(
$this
->
foreignKey
,
$this
->
parent
->
getKey
());
if
(
$touch
)
$this
->
touchIfTouching
();
if
(
$touch
)
{
$this
->
touchIfTouching
();
}
return
count
(
$ids
);
return
count
(
$ids
);
}
}
...
@@ -243,10 +249,8 @@ class BelongsToMany extends EloquentBelongsToMany {
...
@@ -243,10 +249,8 @@ class BelongsToMany extends EloquentBelongsToMany {
// parents without having a possibly slow inner loops for every models.
// parents without having a possibly slow inner loops for every models.
$dictionary
=
[];
$dictionary
=
[];
foreach
(
$results
as
$result
)
foreach
(
$results
as
$result
)
{
{
foreach
(
$result
->
$foreign
as
$item
)
{
foreach
(
$result
->
$foreign
as
$item
)
{
$dictionary
[
$item
][]
=
$result
;
$dictionary
[
$item
][]
=
$result
;
}
}
}
}
...
...
src/Jenssegers/Mongodb/Relations/EmbedsMany.php
View file @
76858f3c
...
@@ -5,7 +5,8 @@ use Illuminate\Pagination\LengthAwarePaginator;
...
@@ -5,7 +5,8 @@ use Illuminate\Pagination\LengthAwarePaginator;
use
Illuminate\Pagination\Paginator
;
use
Illuminate\Pagination\Paginator
;
use
MongoDB\BSON\ObjectID
;
use
MongoDB\BSON\ObjectID
;
class
EmbedsMany
extends
EmbedsOneOrMany
{
class
EmbedsMany
extends
EmbedsOneOrMany
{
/**
/**
* Get the results of the relationship.
* Get the results of the relationship.
...
@@ -26,14 +27,12 @@ class EmbedsMany extends EmbedsOneOrMany {
...
@@ -26,14 +27,12 @@ class EmbedsMany extends EmbedsOneOrMany {
public
function
performInsert
(
Model
$model
)
public
function
performInsert
(
Model
$model
)
{
{
// Generate a new key if needed.
// Generate a new key if needed.
if
(
$model
->
getKeyName
()
==
'_id'
and
!
$model
->
getKey
())
if
(
$model
->
getKeyName
()
==
'_id'
and
!
$model
->
getKey
())
{
{
$model
->
setAttribute
(
'_id'
,
new
ObjectID
);
$model
->
setAttribute
(
'_id'
,
new
ObjectID
);
}
}
// For deeply nested documents, let the parent handle the changes.
// For deeply nested documents, let the parent handle the changes.
if
(
$this
->
isNested
())
if
(
$this
->
isNested
())
{
{
$this
->
associate
(
$model
);
$this
->
associate
(
$model
);
return
$this
->
parent
->
save
();
return
$this
->
parent
->
save
();
...
@@ -43,7 +42,9 @@ class EmbedsMany extends EmbedsOneOrMany {
...
@@ -43,7 +42,9 @@ class EmbedsMany extends EmbedsOneOrMany {
$result
=
$this
->
getBaseQuery
()
->
push
(
$this
->
localKey
,
$model
->
getAttributes
(),
true
);
$result
=
$this
->
getBaseQuery
()
->
push
(
$this
->
localKey
,
$model
->
getAttributes
(),
true
);
// Attach the model to its parent.
// Attach the model to its parent.
if
(
$result
)
$this
->
associate
(
$model
);
if
(
$result
)
{
$this
->
associate
(
$model
);
}
return
$result
?
$model
:
false
;
return
$result
?
$model
:
false
;
}
}
...
@@ -57,8 +58,7 @@ class EmbedsMany extends EmbedsOneOrMany {
...
@@ -57,8 +58,7 @@ class EmbedsMany extends EmbedsOneOrMany {
public
function
performUpdate
(
Model
$model
)
public
function
performUpdate
(
Model
$model
)
{
{
// For deeply nested documents, let the parent handle the changes.
// For deeply nested documents, let the parent handle the changes.
if
(
$this
->
isNested
())
if
(
$this
->
isNested
())
{
{
$this
->
associate
(
$model
);
$this
->
associate
(
$model
);
return
$this
->
parent
->
save
();
return
$this
->
parent
->
save
();
...
@@ -75,7 +75,9 @@ class EmbedsMany extends EmbedsOneOrMany {
...
@@ -75,7 +75,9 @@ class EmbedsMany extends EmbedsOneOrMany {
->
update
(
$values
);
->
update
(
$values
);
// Attach the model to its parent.
// Attach the model to its parent.
if
(
$result
)
$this
->
associate
(
$model
);
if
(
$result
)
{
$this
->
associate
(
$model
);
}
return
$result
?
$model
:
false
;
return
$result
?
$model
:
false
;
}
}
...
@@ -89,8 +91,7 @@ class EmbedsMany extends EmbedsOneOrMany {
...
@@ -89,8 +91,7 @@ class EmbedsMany extends EmbedsOneOrMany {
public
function
performDelete
(
Model
$model
)
public
function
performDelete
(
Model
$model
)
{
{
// For deeply nested documents, let the parent handle the changes.
// For deeply nested documents, let the parent handle the changes.
if
(
$this
->
isNested
())
if
(
$this
->
isNested
())
{
{
$this
->
dissociate
(
$model
);
$this
->
dissociate
(
$model
);
return
$this
->
parent
->
save
();
return
$this
->
parent
->
save
();
...
@@ -101,7 +102,9 @@ class EmbedsMany extends EmbedsOneOrMany {
...
@@ -101,7 +102,9 @@ class EmbedsMany extends EmbedsOneOrMany {
$result
=
$this
->
getBaseQuery
()
->
pull
(
$this
->
localKey
,
[
$model
->
getKeyName
()
=>
$foreignKey
]);
$result
=
$this
->
getBaseQuery
()
->
pull
(
$this
->
localKey
,
[
$model
->
getKeyName
()
=>
$foreignKey
]);
if
(
$result
)
$this
->
dissociate
(
$model
);
if
(
$result
)
{
$this
->
dissociate
(
$model
);
}
return
$result
;
return
$result
;
}
}
...
@@ -114,12 +117,9 @@ class EmbedsMany extends EmbedsOneOrMany {
...
@@ -114,12 +117,9 @@ class EmbedsMany extends EmbedsOneOrMany {
*/
*/
public
function
associate
(
Model
$model
)
public
function
associate
(
Model
$model
)
{
{
if
(
!
$this
->
contains
(
$model
))
if
(
!
$this
->
contains
(
$model
))
{
{
return
$this
->
associateNew
(
$model
);
return
$this
->
associateNew
(
$model
);
}
}
else
{
else
{
return
$this
->
associateExisting
(
$model
);
return
$this
->
associateExisting
(
$model
);
}
}
}
}
...
@@ -139,10 +139,8 @@ class EmbedsMany extends EmbedsOneOrMany {
...
@@ -139,10 +139,8 @@ class EmbedsMany extends EmbedsOneOrMany {
$primaryKey
=
$this
->
related
->
getKeyName
();
$primaryKey
=
$this
->
related
->
getKeyName
();
// Remove the document from the parent model.
// Remove the document from the parent model.
foreach
(
$records
as
$i
=>
$record
)
foreach
(
$records
as
$i
=>
$record
)
{
{
if
(
in_array
(
$record
[
$primaryKey
],
$ids
))
{
if
(
in_array
(
$record
[
$primaryKey
],
$ids
))
{
unset
(
$records
[
$i
]);
unset
(
$records
[
$i
]);
}
}
}
}
...
@@ -171,9 +169,10 @@ class EmbedsMany extends EmbedsOneOrMany {
...
@@ -171,9 +169,10 @@ class EmbedsMany extends EmbedsOneOrMany {
$models
=
$this
->
getResults
()
->
only
(
$ids
);
$models
=
$this
->
getResults
()
->
only
(
$ids
);
// Pull the documents from the database.
// Pull the documents from the database.
foreach
(
$models
as
$model
)
foreach
(
$models
as
$model
)
{
{
if
(
$model
->
delete
())
{
if
(
$model
->
delete
())
$count
++
;
$count
++
;
}
}
}
return
$count
;
return
$count
;
...
@@ -189,7 +188,9 @@ class EmbedsMany extends EmbedsOneOrMany {
...
@@ -189,7 +188,9 @@ class EmbedsMany extends EmbedsOneOrMany {
// Overwrite the local key with an empty array.
// Overwrite the local key with an empty array.
$result
=
$this
->
query
->
update
([
$this
->
localKey
=>
[]]);
$result
=
$this
->
query
->
update
([
$this
->
localKey
=>
[]]);
if
(
$result
)
$this
->
setEmbedded
([]);
if
(
$result
)
{
$this
->
setEmbedded
([]);
}
return
$result
;
return
$result
;
}
}
...
@@ -225,8 +226,7 @@ class EmbedsMany extends EmbedsOneOrMany {
...
@@ -225,8 +226,7 @@ class EmbedsMany extends EmbedsOneOrMany {
protected
function
associateNew
(
$model
)
protected
function
associateNew
(
$model
)
{
{
// Create a new key if needed.
// Create a new key if needed.
if
(
!
$model
->
getAttribute
(
'_id'
))
if
(
!
$model
->
getAttribute
(
'_id'
))
{
{
$model
->
setAttribute
(
'_id'
,
new
ObjectID
);
$model
->
setAttribute
(
'_id'
,
new
ObjectID
);
}
}
...
@@ -254,10 +254,8 @@ class EmbedsMany extends EmbedsOneOrMany {
...
@@ -254,10 +254,8 @@ class EmbedsMany extends EmbedsOneOrMany {
$key
=
$model
->
getKey
();
$key
=
$model
->
getKey
();
// Replace the document in the parent model.
// Replace the document in the parent model.
foreach
(
$records
as
&
$record
)
foreach
(
$records
as
&
$record
)
{
{
if
(
$record
[
$primaryKey
]
==
$key
)
{
if
(
$record
[
$primaryKey
]
==
$key
)
{
$record
=
$model
->
getAttributes
();
$record
=
$model
->
getAttributes
();
break
;
break
;
}
}
...
@@ -306,7 +304,9 @@ class EmbedsMany extends EmbedsOneOrMany {
...
@@ -306,7 +304,9 @@ class EmbedsMany extends EmbedsOneOrMany {
*/
*/
protected
function
setEmbedded
(
$models
)
protected
function
setEmbedded
(
$models
)
{
{
if
(
!
is_array
(
$models
))
$models
=
[
$models
];
if
(
!
is_array
(
$models
))
{
$models
=
[
$models
];
}
return
parent
::
setEmbedded
(
array_values
(
$models
));
return
parent
::
setEmbedded
(
array_values
(
$models
));
}
}
...
@@ -321,12 +321,10 @@ class EmbedsMany extends EmbedsOneOrMany {
...
@@ -321,12 +321,10 @@ class EmbedsMany extends EmbedsOneOrMany {
public
function
__call
(
$method
,
$parameters
)
public
function
__call
(
$method
,
$parameters
)
{
{
// Collection methods
// Collection methods
if
(
method_exists
(
'Jenssegers\Mongodb\Eloquent\Collection'
,
$method
))
if
(
method_exists
(
'Jenssegers\Mongodb\Eloquent\Collection'
,
$method
))
{
{
return
call_user_func_array
([
$this
->
getResults
(),
$method
],
$parameters
);
return
call_user_func_array
([
$this
->
getResults
(),
$method
],
$parameters
);
}
}
return
parent
::
__call
(
$method
,
$parameters
);
return
parent
::
__call
(
$method
,
$parameters
);
}
}
}
}
src/Jenssegers/Mongodb/Relations/EmbedsOne.php
View file @
76858f3c
...
@@ -3,7 +3,8 @@
...
@@ -3,7 +3,8 @@
use
Illuminate\Database\Eloquent\Model
;
use
Illuminate\Database\Eloquent\Model
;
use
MongoDB\BSON\ObjectID
;
use
MongoDB\BSON\ObjectID
;
class
EmbedsOne
extends
EmbedsOneOrMany
{
class
EmbedsOne
extends
EmbedsOneOrMany
{
/**
/**
* Get the results of the relationship.
* Get the results of the relationship.
...
@@ -24,14 +25,12 @@ class EmbedsOne extends EmbedsOneOrMany {
...
@@ -24,14 +25,12 @@ class EmbedsOne extends EmbedsOneOrMany {
public
function
performInsert
(
Model
$model
)
public
function
performInsert
(
Model
$model
)
{
{
// Generate a new key if needed.
// Generate a new key if needed.
if
(
$model
->
getKeyName
()
==
'_id'
and
!
$model
->
getKey
())
if
(
$model
->
getKeyName
()
==
'_id'
and
!
$model
->
getKey
())
{
{
$model
->
setAttribute
(
'_id'
,
new
ObjectID
);
$model
->
setAttribute
(
'_id'
,
new
ObjectID
);
}
}
// For deeply nested documents, let the parent handle the changes.
// For deeply nested documents, let the parent handle the changes.
if
(
$this
->
isNested
())
if
(
$this
->
isNested
())
{
{
$this
->
associate
(
$model
);
$this
->
associate
(
$model
);
return
$this
->
parent
->
save
();
return
$this
->
parent
->
save
();
...
@@ -40,7 +39,9 @@ class EmbedsOne extends EmbedsOneOrMany {
...
@@ -40,7 +39,9 @@ class EmbedsOne extends EmbedsOneOrMany {
$result
=
$this
->
getBaseQuery
()
->
update
([
$this
->
localKey
=>
$model
->
getAttributes
()]);
$result
=
$this
->
getBaseQuery
()
->
update
([
$this
->
localKey
=>
$model
->
getAttributes
()]);
// Attach the model to its parent.
// Attach the model to its parent.
if
(
$result
)
$this
->
associate
(
$model
);
if
(
$result
)
{
$this
->
associate
(
$model
);
}
return
$result
?
$model
:
false
;
return
$result
?
$model
:
false
;
}
}
...
@@ -53,8 +54,7 @@ class EmbedsOne extends EmbedsOneOrMany {
...
@@ -53,8 +54,7 @@ class EmbedsOne extends EmbedsOneOrMany {
*/
*/
public
function
performUpdate
(
Model
$model
)
public
function
performUpdate
(
Model
$model
)
{
{
if
(
$this
->
isNested
())
if
(
$this
->
isNested
())
{
{
$this
->
associate
(
$model
);
$this
->
associate
(
$model
);
return
$this
->
parent
->
save
();
return
$this
->
parent
->
save
();
...
@@ -66,7 +66,9 @@ class EmbedsOne extends EmbedsOneOrMany {
...
@@ -66,7 +66,9 @@ class EmbedsOne extends EmbedsOneOrMany {
$result
=
$this
->
getBaseQuery
()
->
update
(
$values
);
$result
=
$this
->
getBaseQuery
()
->
update
(
$values
);
// Attach the model to its parent.
// Attach the model to its parent.
if
(
$result
)
$this
->
associate
(
$model
);
if
(
$result
)
{
$this
->
associate
(
$model
);
}
return
$result
?
$model
:
false
;
return
$result
?
$model
:
false
;
}
}
...
@@ -80,8 +82,7 @@ class EmbedsOne extends EmbedsOneOrMany {
...
@@ -80,8 +82,7 @@ class EmbedsOne extends EmbedsOneOrMany {
public
function
performDelete
(
Model
$model
)
public
function
performDelete
(
Model
$model
)
{
{
// For deeply nested documents, let the parent handle the changes.
// For deeply nested documents, let the parent handle the changes.
if
(
$this
->
isNested
())
if
(
$this
->
isNested
())
{
{
$this
->
dissociate
(
$model
);
$this
->
dissociate
(
$model
);
return
$this
->
parent
->
save
();
return
$this
->
parent
->
save
();
...
@@ -91,7 +92,9 @@ class EmbedsOne extends EmbedsOneOrMany {
...
@@ -91,7 +92,9 @@ class EmbedsOne extends EmbedsOneOrMany {
$result
=
$this
->
getBaseQuery
()
->
update
([
$this
->
localKey
=>
null
]);
$result
=
$this
->
getBaseQuery
()
->
update
([
$this
->
localKey
=>
null
]);
// Detach the model from its parent.
// Detach the model from its parent.
if
(
$result
)
$this
->
dissociate
();
if
(
$result
)
{
$this
->
dissociate
();
}
return
$result
;
return
$result
;
}
}
...
@@ -128,5 +131,4 @@ class EmbedsOne extends EmbedsOneOrMany {
...
@@ -128,5 +131,4 @@ class EmbedsOne extends EmbedsOneOrMany {
return
$this
->
performDelete
(
$model
);
return
$this
->
performDelete
(
$model
);
}
}
}
}
src/Jenssegers/Mongodb/Relations/EmbedsOneOrMany.php
View file @
76858f3c
...
@@ -6,7 +6,8 @@ use Illuminate\Database\Eloquent\Model;
...
@@ -6,7 +6,8 @@ use Illuminate\Database\Eloquent\Model;
use
Illuminate\Database\Eloquent\Relations\Relation
;
use
Illuminate\Database\Eloquent\Relations\Relation
;
use
Jenssegers\Mongodb\Eloquent\Collection
;
use
Jenssegers\Mongodb\Eloquent\Collection
;
abstract
class
EmbedsOneOrMany
extends
Relation
{
abstract
class
EmbedsOneOrMany
extends
Relation
{
/**
/**
* The local key of the parent model.
* The local key of the parent model.
...
@@ -49,8 +50,7 @@ abstract class EmbedsOneOrMany extends Relation {
...
@@ -49,8 +50,7 @@ abstract class EmbedsOneOrMany extends Relation {
$this
->
relation
=
$relation
;
$this
->
relation
=
$relation
;
// If this is a nested relation, we need to get the parent query instead.
// If this is a nested relation, we need to get the parent query instead.
if
(
$parentRelation
=
$this
->
getParentRelation
())
if
(
$parentRelation
=
$this
->
getParentRelation
())
{
{
$this
->
query
=
$parentRelation
->
getQuery
();
$this
->
query
=
$parentRelation
->
getQuery
();
}
}
...
@@ -62,8 +62,7 @@ abstract class EmbedsOneOrMany extends Relation {
...
@@ -62,8 +62,7 @@ abstract class EmbedsOneOrMany extends Relation {
*/
*/
public
function
addConstraints
()
public
function
addConstraints
()
{
{
if
(
static
::
$constraints
)
if
(
static
::
$constraints
)
{
{
$this
->
query
->
where
(
$this
->
getQualifiedParentKeyName
(),
'='
,
$this
->
getParentKey
());
$this
->
query
->
where
(
$this
->
getQualifiedParentKeyName
(),
'='
,
$this
->
getParentKey
());
}
}
}
}
...
@@ -86,8 +85,7 @@ abstract class EmbedsOneOrMany extends Relation {
...
@@ -86,8 +85,7 @@ abstract class EmbedsOneOrMany extends Relation {
*/
*/
public
function
initRelation
(
array
$models
,
$relation
)
public
function
initRelation
(
array
$models
,
$relation
)
{
{
foreach
(
$models
as
$model
)
foreach
(
$models
as
$model
)
{
{
$model
->
setParentRelation
(
$this
);
$model
->
setParentRelation
(
$this
);
$model
->
setRelation
(
$relation
,
$this
->
related
->
newCollection
());
$model
->
setRelation
(
$relation
,
$this
->
related
->
newCollection
());
...
@@ -106,8 +104,7 @@ abstract class EmbedsOneOrMany extends Relation {
...
@@ -106,8 +104,7 @@ abstract class EmbedsOneOrMany extends Relation {
*/
*/
public
function
match
(
array
$models
,
BaseCollection
$results
,
$relation
)
public
function
match
(
array
$models
,
BaseCollection
$results
,
$relation
)
{
{
foreach
(
$models
as
$model
)
foreach
(
$models
as
$model
)
{
{
$results
=
$model
->
$relation
()
->
getResults
();
$results
=
$model
->
$relation
()
->
getResults
();
$model
->
setParentRelation
(
$this
);
$model
->
setParentRelation
(
$this
);
...
@@ -196,8 +193,7 @@ abstract class EmbedsOneOrMany extends Relation {
...
@@ -196,8 +193,7 @@ abstract class EmbedsOneOrMany extends Relation {
{
{
$instances
=
[];
$instances
=
[];
foreach
(
$records
as
$record
)
foreach
(
$records
as
$record
)
{
{
$instances
[]
=
$this
->
create
(
$record
);
$instances
[]
=
$this
->
create
(
$record
);
}
}
...
@@ -212,16 +208,18 @@ abstract class EmbedsOneOrMany extends Relation {
...
@@ -212,16 +208,18 @@ abstract class EmbedsOneOrMany extends Relation {
*/
*/
protected
function
getIdsArrayFrom
(
$ids
)
protected
function
getIdsArrayFrom
(
$ids
)
{
{
if
(
$ids
instanceof
\Illuminate\Support\Collection
)
if
(
$ids
instanceof
\Illuminate\Support\Collection
)
{
{
$ids
=
$ids
->
all
();
$ids
=
$ids
->
all
();
}
}
if
(
!
is_array
(
$ids
))
$ids
=
[
$ids
];
if
(
!
is_array
(
$ids
))
{
$ids
=
[
$ids
];
}
foreach
(
$ids
as
&
$id
)
foreach
(
$ids
as
&
$id
)
{
{
if
(
$id
instanceof
Model
)
{
if
(
$id
instanceof
Model
)
$id
=
$id
->
getKey
();
$id
=
$id
->
getKey
();
}
}
}
return
$ids
;
return
$ids
;
...
@@ -270,8 +268,7 @@ abstract class EmbedsOneOrMany extends Relation {
...
@@ -270,8 +268,7 @@ abstract class EmbedsOneOrMany extends Relation {
*/
*/
protected
function
getForeignKeyValue
(
$id
)
protected
function
getForeignKeyValue
(
$id
)
{
{
if
(
$id
instanceof
Model
)
if
(
$id
instanceof
Model
)
{
{
$id
=
$id
->
getKey
();
$id
=
$id
->
getKey
();
}
}
...
@@ -289,13 +286,11 @@ abstract class EmbedsOneOrMany extends Relation {
...
@@ -289,13 +286,11 @@ abstract class EmbedsOneOrMany extends Relation {
{
{
$models
=
[];
$models
=
[];
foreach
(
$records
as
$attributes
)
foreach
(
$records
as
$attributes
)
{
{
$models
[]
=
$this
->
toModel
(
$attributes
);
$models
[]
=
$this
->
toModel
(
$attributes
);
}
}
if
(
count
(
$models
)
>
0
)
if
(
count
(
$models
)
>
0
)
{
{
$models
=
$this
->
eagerLoadRelations
(
$models
);
$models
=
$this
->
eagerLoadRelations
(
$models
);
}
}
...
@@ -310,7 +305,9 @@ abstract class EmbedsOneOrMany extends Relation {
...
@@ -310,7 +305,9 @@ abstract class EmbedsOneOrMany extends Relation {
*/
*/
protected
function
toModel
(
$attributes
=
[])
protected
function
toModel
(
$attributes
=
[])
{
{
if
(
is_null
(
$attributes
))
return
;
if
(
is_null
(
$attributes
))
{
return
;
}
$model
=
$this
->
related
->
newFromBuilder
((
array
)
$attributes
);
$model
=
$this
->
related
->
newFromBuilder
((
array
)
$attributes
);
...
@@ -376,8 +373,7 @@ abstract class EmbedsOneOrMany extends Relation {
...
@@ -376,8 +373,7 @@ abstract class EmbedsOneOrMany extends Relation {
*/
*/
protected
function
getPathHierarchy
(
$glue
=
'.'
)
protected
function
getPathHierarchy
(
$glue
=
'.'
)
{
{
if
(
$parentRelation
=
$this
->
getParentRelation
())
if
(
$parentRelation
=
$this
->
getParentRelation
())
{
{
return
$parentRelation
->
getPathHierarchy
(
$glue
)
.
$glue
.
$this
->
localKey
;
return
$parentRelation
->
getPathHierarchy
(
$glue
)
.
$glue
.
$this
->
localKey
;
}
}
...
@@ -391,8 +387,7 @@ abstract class EmbedsOneOrMany extends Relation {
...
@@ -391,8 +387,7 @@ abstract class EmbedsOneOrMany extends Relation {
*/
*/
public
function
getQualifiedParentKeyName
()
public
function
getQualifiedParentKeyName
()
{
{
if
(
$parentRelation
=
$this
->
getParentRelation
())
if
(
$parentRelation
=
$this
->
getParentRelation
())
{
{
return
$parentRelation
->
getPathHierarchy
()
.
'.'
.
$this
->
parent
->
getKeyName
();
return
$parentRelation
->
getPathHierarchy
()
.
'.'
.
$this
->
parent
->
getKeyName
();
}
}
...
@@ -408,5 +403,4 @@ abstract class EmbedsOneOrMany extends Relation {
...
@@ -408,5 +403,4 @@ abstract class EmbedsOneOrMany extends Relation {
{
{
return
$this
->
parent
->
getKey
();
return
$this
->
parent
->
getKey
();
}
}
}
}
src/Jenssegers/Mongodb/Relations/HasMany.php
View file @
76858f3c
...
@@ -3,7 +3,8 @@
...
@@ -3,7 +3,8 @@
use
Illuminate\Database\Eloquent\Builder
;
use
Illuminate\Database\Eloquent\Builder
;
use
Illuminate\Database\Eloquent\Relations\HasMany
as
EloquentHasMany
;
use
Illuminate\Database\Eloquent\Relations\HasMany
as
EloquentHasMany
;
class
HasMany
extends
EloquentHasMany
{
class
HasMany
extends
EloquentHasMany
{
/**
/**
* Add the constraints for a relationship count query.
* Add the constraints for a relationship count query.
...
@@ -43,5 +44,4 @@ class HasMany extends EloquentHasMany {
...
@@ -43,5 +44,4 @@ class HasMany extends EloquentHasMany {
{
{
return
$this
->
getForeignKey
();
return
$this
->
getForeignKey
();
}
}
}
}
src/Jenssegers/Mongodb/Relations/HasOne.php
View file @
76858f3c
...
@@ -3,7 +3,8 @@
...
@@ -3,7 +3,8 @@
use
Illuminate\Database\Eloquent\Builder
;
use
Illuminate\Database\Eloquent\Builder
;
use
Illuminate\Database\Eloquent\Relations\HasOne
as
EloquentHasOne
;
use
Illuminate\Database\Eloquent\Relations\HasOne
as
EloquentHasOne
;
class
HasOne
extends
EloquentHasOne
{
class
HasOne
extends
EloquentHasOne
{
/**
/**
* Add the constraints for a relationship count query.
* Add the constraints for a relationship count query.
...
@@ -43,5 +44,4 @@ class HasOne extends EloquentHasOne {
...
@@ -43,5 +44,4 @@ class HasOne extends EloquentHasOne {
{
{
return
$this
->
getForeignKey
();
return
$this
->
getForeignKey
();
}
}
}
}
src/Jenssegers/Mongodb/Relations/MorphTo.php
View file @
76858f3c
...
@@ -2,15 +2,15 @@
...
@@ -2,15 +2,15 @@
use
Illuminate\Database\Eloquent\Relations\MorphTo
as
EloquentMorphTo
;
use
Illuminate\Database\Eloquent\Relations\MorphTo
as
EloquentMorphTo
;
class
MorphTo
extends
EloquentMorphTo
{
class
MorphTo
extends
EloquentMorphTo
{
/**
/**
* Set the base constraints on the relation query.
* Set the base constraints on the relation query.
*/
*/
public
function
addConstraints
()
public
function
addConstraints
()
{
{
if
(
static
::
$constraints
)
if
(
static
::
$constraints
)
{
{
// For belongs to relationships, which are essentially the inverse of has one
// For belongs to relationships, which are essentially the inverse of has one
// or has many relationships, we need to actually query on the primary key
// or has many relationships, we need to actually query on the primary key
// of the related models matching on the foreign key that's on a parent.
// of the related models matching on the foreign key that's on a parent.
...
@@ -36,5 +36,4 @@ class MorphTo extends EloquentMorphTo {
...
@@ -36,5 +36,4 @@ class MorphTo extends EloquentMorphTo {
return
$query
->
whereIn
(
$key
,
$this
->
gatherKeysByType
(
$type
)
->
all
())
->
get
();
return
$query
->
whereIn
(
$key
,
$this
->
gatherKeysByType
(
$type
)
->
all
())
->
get
();
}
}
}
}
src/Jenssegers/Mongodb/Schema/Blueprint.php
View file @
76858f3c
...
@@ -3,7 +3,8 @@
...
@@ -3,7 +3,8 @@
use
Closure
;
use
Closure
;
use
Illuminate\Database\Connection
;
use
Illuminate\Database\Connection
;
class
Blueprint
extends
\Illuminate\Database\Schema\Blueprint
{
class
Blueprint
extends
\Illuminate\Database\Schema\Blueprint
{
/**
/**
* The MongoConnection object for this blueprint.
* The MongoConnection object for this blueprint.
...
@@ -51,13 +52,11 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
...
@@ -51,13 +52,11 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
$columns
=
$this
->
fluent
(
$columns
);
$columns
=
$this
->
fluent
(
$columns
);
// Columns are passed as a default array.
// Columns are passed as a default array.
if
(
is_array
(
$columns
)
&&
is_int
(
key
(
$columns
)))
if
(
is_array
(
$columns
)
&&
is_int
(
key
(
$columns
)))
{
{
// Transform the columns to the required array format.
// Transform the columns to the required array format.
$transform
=
[];
$transform
=
[];
foreach
(
$columns
as
$column
)
foreach
(
$columns
as
$column
)
{
{
$transform
[
$column
]
=
1
;
$transform
[
$column
]
=
1
;
}
}
...
@@ -92,21 +91,18 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
...
@@ -92,21 +91,18 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
$columns
=
$this
->
fluent
(
$columns
);
$columns
=
$this
->
fluent
(
$columns
);
// Columns are passed as a default array.
// Columns are passed as a default array.
if
(
is_array
(
$columns
)
&&
is_int
(
key
(
$columns
)))
if
(
is_array
(
$columns
)
&&
is_int
(
key
(
$columns
)))
{
{
// Transform the columns to the required array format.
// Transform the columns to the required array format.
$transform
=
[];
$transform
=
[];
foreach
(
$columns
as
$column
)
foreach
(
$columns
as
$column
)
{
{
$transform
[
$column
]
=
$column
.
'_1'
;
$transform
[
$column
]
=
$column
.
'_1'
;
}
}
$columns
=
$transform
;
$columns
=
$transform
;
}
}
foreach
(
$columns
as
$column
)
foreach
(
$columns
as
$column
)
{
{
$this
->
collection
->
dropIndex
(
$column
);
$this
->
collection
->
dropIndex
(
$column
);
}
}
...
@@ -229,16 +225,11 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
...
@@ -229,16 +225,11 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
*/
*/
protected
function
fluent
(
$columns
=
null
)
protected
function
fluent
(
$columns
=
null
)
{
{
if
(
is_null
(
$columns
))
if
(
is_null
(
$columns
))
{
{
return
$this
->
columns
;
return
$this
->
columns
;
}
}
elseif
(
is_string
(
$columns
))
{
elseif
(
is_string
(
$columns
))
{
return
$this
->
columns
=
[
$columns
];
return
$this
->
columns
=
[
$columns
];
}
}
else
{
else
{
return
$this
->
columns
=
$columns
;
return
$this
->
columns
=
$columns
;
}
}
}
}
...
@@ -253,5 +244,4 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
...
@@ -253,5 +244,4 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
// Dummy.
// Dummy.
return
$this
;
return
$this
;
}
}
}
}
src/Jenssegers/Mongodb/Schema/Builder.php
View file @
76858f3c
...
@@ -3,7 +3,8 @@
...
@@ -3,7 +3,8 @@
use
Closure
;
use
Closure
;
use
Jenssegers\Mongodb\Connection
;
use
Jenssegers\Mongodb\Connection
;
class
Builder
extends
\Illuminate\Database\Schema\Builder
{
class
Builder
extends
\Illuminate\Database\Schema\Builder
{
/**
/**
* Create a new database Schema manager.
* Create a new database Schema manager.
...
@@ -49,8 +50,8 @@ class Builder extends \Illuminate\Database\Schema\Builder {
...
@@ -49,8 +50,8 @@ class Builder extends \Illuminate\Database\Schema\Builder {
{
{
$db
=
$this
->
connection
->
getMongoDB
();
$db
=
$this
->
connection
->
getMongoDB
();
foreach
(
$db
->
listCollections
()
as
$collectionFromMongo
)
{
foreach
(
$db
->
listCollections
()
as
$collectionFromMongo
)
{
if
(
$collectionFromMongo
->
getName
()
==
$collection
)
{
if
(
$collectionFromMongo
->
getName
()
==
$collection
)
{
return
true
;
return
true
;
}
}
}
}
...
@@ -80,8 +81,7 @@ class Builder extends \Illuminate\Database\Schema\Builder {
...
@@ -80,8 +81,7 @@ class Builder extends \Illuminate\Database\Schema\Builder {
{
{
$blueprint
=
$this
->
createBlueprint
(
$collection
);
$blueprint
=
$this
->
createBlueprint
(
$collection
);
if
(
$callback
)
if
(
$callback
)
{
{
$callback
(
$blueprint
);
$callback
(
$blueprint
);
}
}
}
}
...
@@ -111,8 +111,7 @@ class Builder extends \Illuminate\Database\Schema\Builder {
...
@@ -111,8 +111,7 @@ class Builder extends \Illuminate\Database\Schema\Builder {
$blueprint
->
create
();
$blueprint
->
create
();
if
(
$callback
)
if
(
$callback
)
{
{
$callback
(
$blueprint
);
$callback
(
$blueprint
);
}
}
}
}
...
@@ -140,5 +139,4 @@ class Builder extends \Illuminate\Database\Schema\Builder {
...
@@ -140,5 +139,4 @@ class Builder extends \Illuminate\Database\Schema\Builder {
{
{
return
new
Blueprint
(
$this
->
connection
,
$collection
);
return
new
Blueprint
(
$this
->
connection
,
$collection
);
}
}
}
}
tests/AuthTest.php
View file @
76858f3c
...
@@ -2,7 +2,8 @@
...
@@ -2,7 +2,8 @@
use
Illuminate\Auth\Passwords\PasswordBroker
;
use
Illuminate\Auth\Passwords\PasswordBroker
;
class
AuthTest
extends
TestCase
{
class
AuthTest
extends
TestCase
{
public
function
tearDown
()
public
function
tearDown
()
{
{
...
@@ -52,8 +53,7 @@ class AuthTest extends TestCase {
...
@@ -52,8 +53,7 @@ class AuthTest extends TestCase {
'token'
=>
$reminder
[
'token'
],
'token'
=>
$reminder
[
'token'
],
];
];
$response
=
$broker
->
reset
(
$credentials
,
function
(
$user
,
$password
)
$response
=
$broker
->
reset
(
$credentials
,
function
(
$user
,
$password
)
{
{
$user
->
password
=
bcrypt
(
$password
);
$user
->
password
=
bcrypt
(
$password
);
$user
->
save
();
$user
->
save
();
});
});
...
@@ -61,5 +61,4 @@ class AuthTest extends TestCase {
...
@@ -61,5 +61,4 @@ class AuthTest extends TestCase {
$this
->
assertEquals
(
'passwords.reset'
,
$response
);
$this
->
assertEquals
(
'passwords.reset'
,
$response
);
$this
->
assertEquals
(
0
,
DB
::
collection
(
'password_resets'
)
->
count
());
$this
->
assertEquals
(
0
,
DB
::
collection
(
'password_resets'
)
->
count
());
}
}
}
}
tests/ConnectionTest.php
View file @
76858f3c
<?php
<?php
class
ConnectionTest
extends
TestCase
{
class
ConnectionTest
extends
TestCase
{
public
function
testConnection
()
public
function
testConnection
()
{
{
...
@@ -129,5 +130,4 @@ class ConnectionTest extends TestCase {
...
@@ -129,5 +130,4 @@ class ConnectionTest extends TestCase {
// $this->setExpectedException('MongoConnectionException', "Failed to connect to: " . $hosts[0] . ": Connection refused; Failed to connect to: " . $hosts[1] . ": Connection refused");
// $this->setExpectedException('MongoConnectionException', "Failed to connect to: " . $hosts[0] . ": Connection refused; Failed to connect to: " . $hosts[1] . ": Connection refused");
$connection
=
DB
::
connection
(
'mongodb'
);
$connection
=
DB
::
connection
(
'mongodb'
);
}
}
}
}
tests/EmbeddedRelationsTest.php
View file @
76858f3c
<?php
<?php
class
EmbeddedRelationsTest
extends
TestCase
{
class
EmbeddedRelationsTest
extends
TestCase
{
public
function
tearDown
()
public
function
tearDown
()
{
{
...
@@ -748,5 +749,4 @@ class EmbeddedRelationsTest extends TestCase {
...
@@ -748,5 +749,4 @@ class EmbeddedRelationsTest extends TestCase {
$this
->
assertEquals
(
2
,
$results
->
count
());
$this
->
assertEquals
(
2
,
$results
->
count
());
$this
->
assertEquals
(
3
,
$results
->
total
());
$this
->
assertEquals
(
3
,
$results
->
total
());
}
}
}
}
tests/ModelTest.php
View file @
76858f3c
<?php
<?php
class
ModelTest
extends
TestCase
{
class
ModelTest
extends
TestCase
{
public
function
tearDown
()
public
function
tearDown
()
{
{
...
@@ -331,7 +332,8 @@ class ModelTest extends TestCase {
...
@@ -331,7 +332,8 @@ class ModelTest extends TestCase {
$item
=
Item
::
create
([
'name'
=>
'fork'
,
'type'
=>
'sharp'
]);
$item
=
Item
::
create
([
'name'
=>
'fork'
,
'type'
=>
'sharp'
]);
$array
=
$item
->
toArray
();
$array
=
$item
->
toArray
();
$keys
=
array_keys
(
$array
);
sort
(
$keys
);
$keys
=
array_keys
(
$array
);
sort
(
$keys
);
$this
->
assertEquals
([
'_id'
,
'created_at'
,
'name'
,
'type'
,
'updated_at'
],
$keys
);
$this
->
assertEquals
([
'_id'
,
'created_at'
,
'name'
,
'type'
,
'updated_at'
],
$keys
);
$this
->
assertTrue
(
is_string
(
$array
[
'created_at'
]));
$this
->
assertTrue
(
is_string
(
$array
[
'created_at'
]));
$this
->
assertTrue
(
is_string
(
$array
[
'updated_at'
]));
$this
->
assertTrue
(
is_string
(
$array
[
'updated_at'
]));
...
@@ -449,28 +451,24 @@ class ModelTest extends TestCase {
...
@@ -449,28 +451,24 @@ class ModelTest extends TestCase {
User
::
create
([
'name'
=>
'Jane Doe'
,
'age'
=>
35
]);
User
::
create
([
'name'
=>
'Jane Doe'
,
'age'
=>
35
]);
User
::
create
([
'name'
=>
'Harry Hoe'
,
'age'
=>
15
]);
User
::
create
([
'name'
=>
'Harry Hoe'
,
'age'
=>
15
]);
$users
=
User
::
raw
(
function
(
$collection
)
$users
=
User
::
raw
(
function
(
$collection
)
{
{
return
$collection
->
find
([
'age'
=>
35
]);
return
$collection
->
find
([
'age'
=>
35
]);
});
});
$this
->
assertInstanceOf
(
'Illuminate\Database\Eloquent\Collection'
,
$users
);
$this
->
assertInstanceOf
(
'Illuminate\Database\Eloquent\Collection'
,
$users
);
$this
->
assertInstanceOf
(
'Jenssegers\Mongodb\Eloquent\Model'
,
$users
[
0
]);
$this
->
assertInstanceOf
(
'Jenssegers\Mongodb\Eloquent\Model'
,
$users
[
0
]);
$user
=
User
::
raw
(
function
(
$collection
)
$user
=
User
::
raw
(
function
(
$collection
)
{
{
return
$collection
->
findOne
([
'age'
=>
35
]);
return
$collection
->
findOne
([
'age'
=>
35
]);
});
});
$this
->
assertInstanceOf
(
'Jenssegers\Mongodb\Eloquent\Model'
,
$user
);
$this
->
assertInstanceOf
(
'Jenssegers\Mongodb\Eloquent\Model'
,
$user
);
$count
=
User
::
raw
(
function
(
$collection
)
$count
=
User
::
raw
(
function
(
$collection
)
{
{
return
$collection
->
count
();
return
$collection
->
count
();
});
});
$this
->
assertEquals
(
3
,
$count
);
$this
->
assertEquals
(
3
,
$count
);
$result
=
User
::
raw
(
function
(
$collection
)
$result
=
User
::
raw
(
function
(
$collection
)
{
{
return
$collection
->
insertOne
([
'name'
=>
'Yvonne Yoe'
,
'age'
=>
35
]);
return
$collection
->
insertOne
([
'name'
=>
'Yvonne Yoe'
,
'age'
=>
35
]);
});
});
$this
->
assertNotNull
(
$result
);
$this
->
assertNotNull
(
$result
);
...
@@ -500,5 +498,4 @@ class ModelTest extends TestCase {
...
@@ -500,5 +498,4 @@ class ModelTest extends TestCase {
$user
->
birthday
=
new
DateTime
(
'19 august 1989'
);
$user
->
birthday
=
new
DateTime
(
'19 august 1989'
);
$this
->
assertEmpty
(
$user
->
getDirty
());
$this
->
assertEmpty
(
$user
->
getDirty
());
}
}
}
}
tests/MysqlRelationsTest.php
View file @
76858f3c
<?php
<?php
class
MysqlRelationsTest
extends
TestCase
{
class
MysqlRelationsTest
extends
TestCase
{
public
function
setUp
()
public
function
setUp
()
{
{
...
...
tests/QueryBuilderTest.php
View file @
76858f3c
...
@@ -3,7 +3,8 @@
...
@@ -3,7 +3,8 @@
use
MongoDB\BSON\UTCDateTime
;
use
MongoDB\BSON\UTCDateTime
;
use
MongoDB\BSON\Regex
;
use
MongoDB\BSON\Regex
;
class
QueryBuilderTest
extends
TestCase
{
class
QueryBuilderTest
extends
TestCase
{
public
function
tearDown
()
public
function
tearDown
()
{
{
...
@@ -182,8 +183,7 @@ class QueryBuilderTest extends TestCase {
...
@@ -182,8 +183,7 @@ class QueryBuilderTest extends TestCase {
[
'name'
=>
'John Doe'
,
'age'
=>
25
],
[
'name'
=>
'John Doe'
,
'age'
=>
25
],
]);
]);
$cursor
=
DB
::
collection
(
'users'
)
->
raw
(
function
(
$collection
)
$cursor
=
DB
::
collection
(
'users'
)
->
raw
(
function
(
$collection
)
{
{
return
$collection
->
find
([
'age'
=>
20
]);
return
$collection
->
find
([
'age'
=>
20
]);
});
});
...
@@ -289,11 +289,13 @@ class QueryBuilderTest extends TestCase {
...
@@ -289,11 +289,13 @@ class QueryBuilderTest extends TestCase {
[
'name'
=>
'spoon'
,
'type'
=>
'round'
],
[
'name'
=>
'spoon'
,
'type'
=>
'round'
],
]);
]);
$items
=
DB
::
collection
(
'items'
)
->
distinct
(
'name'
)
->
get
();
sort
(
$items
);
$items
=
DB
::
collection
(
'items'
)
->
distinct
(
'name'
)
->
get
();
sort
(
$items
);
$this
->
assertEquals
(
3
,
count
(
$items
));
$this
->
assertEquals
(
3
,
count
(
$items
));
$this
->
assertEquals
([
'fork'
,
'knife'
,
'spoon'
],
$items
);
$this
->
assertEquals
([
'fork'
,
'knife'
,
'spoon'
],
$items
);
$types
=
DB
::
collection
(
'items'
)
->
distinct
(
'type'
)
->
get
();
sort
(
$types
);
$types
=
DB
::
collection
(
'items'
)
->
distinct
(
'type'
)
->
get
();
sort
(
$types
);
$this
->
assertEquals
(
2
,
count
(
$types
));
$this
->
assertEquals
(
2
,
count
(
$types
));
$this
->
assertEquals
([
'round'
,
'sharp'
],
$types
);
$this
->
assertEquals
([
'round'
,
'sharp'
],
$types
);
}
}
...
@@ -638,10 +640,8 @@ class QueryBuilderTest extends TestCase {
...
@@ -638,10 +640,8 @@ class QueryBuilderTest extends TestCase {
$results
=
DB
::
collection
(
'items'
)
->
project
([
'tags'
=>
[
'$slice'
=>
1
]])
->
get
();
$results
=
DB
::
collection
(
'items'
)
->
project
([
'tags'
=>
[
'$slice'
=>
1
]])
->
get
();
foreach
(
$results
as
$result
)
foreach
(
$results
as
$result
)
{
{
$this
->
assertEquals
(
1
,
count
(
$result
[
'tags'
]));
$this
->
assertEquals
(
1
,
count
(
$result
[
'tags'
]));
}
}
}
}
}
}
tests/QueryTest.php
View file @
76858f3c
<?php
<?php
class
QueryTest
extends
TestCase
{
class
QueryTest
extends
TestCase
{
protected
static
$started
=
false
;
protected
static
$started
=
false
;
...
@@ -214,8 +215,7 @@ class QueryTest extends TestCase {
...
@@ -214,8 +215,7 @@ class QueryTest extends TestCase {
public
function
testSubquery
()
public
function
testSubquery
()
{
{
$users
=
User
::
where
(
'title'
,
'admin'
)
->
orWhere
(
function
(
$query
)
$users
=
User
::
where
(
'title'
,
'admin'
)
->
orWhere
(
function
(
$query
)
{
{
$query
->
where
(
'name'
,
'Tommy Toe'
)
$query
->
where
(
'name'
,
'Tommy Toe'
)
->
orWhere
(
'name'
,
'Error'
);
->
orWhere
(
'name'
,
'Error'
);
})
})
...
@@ -223,8 +223,7 @@ class QueryTest extends TestCase {
...
@@ -223,8 +223,7 @@ class QueryTest extends TestCase {
$this
->
assertEquals
(
5
,
count
(
$users
));
$this
->
assertEquals
(
5
,
count
(
$users
));
$users
=
User
::
where
(
'title'
,
'user'
)
->
where
(
function
(
$query
)
$users
=
User
::
where
(
'title'
,
'user'
)
->
where
(
function
(
$query
)
{
{
$query
->
where
(
'age'
,
35
)
$query
->
where
(
'age'
,
35
)
->
orWhere
(
'name'
,
'like'
,
'%harry%'
);
->
orWhere
(
'name'
,
'like'
,
'%harry%'
);
})
})
...
@@ -232,8 +231,7 @@ class QueryTest extends TestCase {
...
@@ -232,8 +231,7 @@ class QueryTest extends TestCase {
$this
->
assertEquals
(
2
,
count
(
$users
));
$this
->
assertEquals
(
2
,
count
(
$users
));
$users
=
User
::
where
(
'age'
,
35
)
->
orWhere
(
function
(
$query
)
$users
=
User
::
where
(
'age'
,
35
)
->
orWhere
(
function
(
$query
)
{
{
$query
->
where
(
'title'
,
'admin'
)
$query
->
where
(
'title'
,
'admin'
)
->
orWhere
(
'name'
,
'Error'
);
->
orWhere
(
'name'
,
'Error'
);
})
})
...
@@ -243,8 +241,7 @@ class QueryTest extends TestCase {
...
@@ -243,8 +241,7 @@ class QueryTest extends TestCase {
$users
=
User
::
whereNull
(
'deleted_at'
)
$users
=
User
::
whereNull
(
'deleted_at'
)
->
where
(
'title'
,
'admin'
)
->
where
(
'title'
,
'admin'
)
->
where
(
function
(
$query
)
->
where
(
function
(
$query
)
{
{
$query
->
where
(
'age'
,
'>'
,
15
)
$query
->
where
(
'age'
,
'>'
,
15
)
->
orWhere
(
'name'
,
'Harry Hoe'
);
->
orWhere
(
'name'
,
'Harry Hoe'
);
})
})
...
@@ -253,11 +250,9 @@ class QueryTest extends TestCase {
...
@@ -253,11 +250,9 @@ class QueryTest extends TestCase {
$this
->
assertEquals
(
3
,
$users
->
count
());
$this
->
assertEquals
(
3
,
$users
->
count
());
$users
=
User
::
whereNull
(
'deleted_at'
)
$users
=
User
::
whereNull
(
'deleted_at'
)
->
where
(
function
(
$query
)
->
where
(
function
(
$query
)
{
{
$query
->
where
(
'name'
,
'Harry Hoe'
)
$query
->
where
(
'name'
,
'Harry Hoe'
)
->
orWhere
(
function
(
$query
)
->
orWhere
(
function
(
$query
)
{
{
$query
->
where
(
'age'
,
'>'
,
15
)
$query
->
where
(
'age'
,
'>'
,
15
)
->
where
(
'title'
,
'<>'
,
'admin'
);
->
where
(
'title'
,
'<>'
,
'admin'
);
});
});
...
@@ -283,23 +278,19 @@ class QueryTest extends TestCase {
...
@@ -283,23 +278,19 @@ class QueryTest extends TestCase {
public
function
testMultipleOr
()
public
function
testMultipleOr
()
{
{
$users
=
User
::
where
(
function
(
$query
)
$users
=
User
::
where
(
function
(
$query
)
{
{
$query
->
where
(
'age'
,
35
)
->
orWhere
(
'age'
,
33
);
$query
->
where
(
'age'
,
35
)
->
orWhere
(
'age'
,
33
);
})
})
->
where
(
function
(
$query
)
->
where
(
function
(
$query
)
{
{
$query
->
where
(
'name'
,
'John Doe'
)
->
orWhere
(
'name'
,
'Jane Doe'
);
$query
->
where
(
'name'
,
'John Doe'
)
->
orWhere
(
'name'
,
'Jane Doe'
);
})
->
get
();
})
->
get
();
$this
->
assertEquals
(
2
,
count
(
$users
));
$this
->
assertEquals
(
2
,
count
(
$users
));
$users
=
User
::
where
(
function
(
$query
)
$users
=
User
::
where
(
function
(
$query
)
{
{
$query
->
orWhere
(
'age'
,
35
)
->
orWhere
(
'age'
,
33
);
$query
->
orWhere
(
'age'
,
35
)
->
orWhere
(
'age'
,
33
);
})
})
->
where
(
function
(
$query
)
->
where
(
function
(
$query
)
{
{
$query
->
orWhere
(
'name'
,
'John Doe'
)
->
orWhere
(
'name'
,
'Jane Doe'
);
$query
->
orWhere
(
'name'
,
'John Doe'
)
->
orWhere
(
'name'
,
'Jane Doe'
);
})
->
get
();
})
->
get
();
...
@@ -319,5 +310,4 @@ class QueryTest extends TestCase {
...
@@ -319,5 +310,4 @@ class QueryTest extends TestCase {
$this
->
assertEquals
(
9
,
$results
->
total
());
$this
->
assertEquals
(
9
,
$results
->
total
());
$this
->
assertEquals
(
1
,
$results
->
currentPage
());
$this
->
assertEquals
(
1
,
$results
->
currentPage
());
}
}
}
}
tests/RelationsTest.php
View file @
76858f3c
<?php
<?php
class
RelationsTest
extends
TestCase
{
class
RelationsTest
extends
TestCase
{
public
function
tearDown
()
public
function
tearDown
()
{
{
...
@@ -410,15 +411,13 @@ class RelationsTest extends TestCase {
...
@@ -410,15 +411,13 @@ class RelationsTest extends TestCase {
$authors
=
User
::
has
(
'books'
,
'!='
,
0
)
->
get
();
$authors
=
User
::
has
(
'books'
,
'!='
,
0
)
->
get
();
$this
->
assertCount
(
2
,
$authors
);
$this
->
assertCount
(
2
,
$authors
);
$authors
=
User
::
whereHas
(
'books'
,
function
(
$query
)
$authors
=
User
::
whereHas
(
'books'
,
function
(
$query
)
{
{
$query
->
where
(
'rating'
,
5
);
$query
->
where
(
'rating'
,
5
);
})
->
get
();
})
->
get
();
$this
->
assertCount
(
1
,
$authors
);
$this
->
assertCount
(
1
,
$authors
);
$authors
=
User
::
whereHas
(
'books'
,
function
(
$query
)
$authors
=
User
::
whereHas
(
'books'
,
function
(
$query
)
{
{
$query
->
where
(
'rating'
,
'<'
,
5
);
$query
->
where
(
'rating'
,
'<'
,
5
);
})
->
get
();
})
->
get
();
...
@@ -521,5 +520,4 @@ class RelationsTest extends TestCase {
...
@@ -521,5 +520,4 @@ class RelationsTest extends TestCase {
$this
->
assertEquals
([
$user
->
_id
],
$client
->
user_ids
);
$this
->
assertEquals
([
$user
->
_id
],
$client
->
user_ids
);
$this
->
assertEquals
([
$client
->
_id
],
$user
->
client_ids
);
$this
->
assertEquals
([
$client
->
_id
],
$user
->
client_ids
);
}
}
}
}
tests/SchemaTest.php
View file @
76858f3c
<?php
<?php
class
SchemaTest
extends
TestCase
{
class
SchemaTest
extends
TestCase
{
public
function
tearDown
()
public
function
tearDown
()
{
{
...
@@ -18,8 +19,7 @@ class SchemaTest extends TestCase {
...
@@ -18,8 +19,7 @@ class SchemaTest extends TestCase {
{
{
$instance
=
$this
;
$instance
=
$this
;
Schema
::
create
(
'newcollection'
,
function
(
$collection
)
use
(
$instance
)
Schema
::
create
(
'newcollection'
,
function
(
$collection
)
use
(
$instance
)
{
{
$instance
->
assertInstanceOf
(
'Jenssegers\Mongodb\Schema\Blueprint'
,
$collection
);
$instance
->
assertInstanceOf
(
'Jenssegers\Mongodb\Schema\Blueprint'
,
$collection
);
});
});
...
@@ -37,37 +37,32 @@ class SchemaTest extends TestCase {
...
@@ -37,37 +37,32 @@ class SchemaTest extends TestCase {
{
{
$instance
=
$this
;
$instance
=
$this
;
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
use
(
$instance
)
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
use
(
$instance
)
{
{
$instance
->
assertInstanceOf
(
'Jenssegers\Mongodb\Schema\Blueprint'
,
$collection
);
$instance
->
assertInstanceOf
(
'Jenssegers\Mongodb\Schema\Blueprint'
,
$collection
);
});
});
Schema
::
table
(
'newcollection'
,
function
(
$collection
)
use
(
$instance
)
Schema
::
table
(
'newcollection'
,
function
(
$collection
)
use
(
$instance
)
{
{
$instance
->
assertInstanceOf
(
'Jenssegers\Mongodb\Schema\Blueprint'
,
$collection
);
$instance
->
assertInstanceOf
(
'Jenssegers\Mongodb\Schema\Blueprint'
,
$collection
);
});
});
}
}
public
function
testIndex
()
public
function
testIndex
()
{
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
{
$collection
->
index
(
'mykey1'
);
$collection
->
index
(
'mykey1'
);
});
});
$index
=
$this
->
getIndex
(
'newcollection'
,
'mykey1'
);
$index
=
$this
->
getIndex
(
'newcollection'
,
'mykey1'
);
$this
->
assertEquals
(
1
,
$index
[
'key'
][
'mykey1'
]);
$this
->
assertEquals
(
1
,
$index
[
'key'
][
'mykey1'
]);
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
{
$collection
->
index
([
'mykey2'
]);
$collection
->
index
([
'mykey2'
]);
});
});
$index
=
$this
->
getIndex
(
'newcollection'
,
'mykey2'
);
$index
=
$this
->
getIndex
(
'newcollection'
,
'mykey2'
);
$this
->
assertEquals
(
1
,
$index
[
'key'
][
'mykey2'
]);
$this
->
assertEquals
(
1
,
$index
[
'key'
][
'mykey2'
]);
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
{
$collection
->
string
(
'mykey3'
)
->
index
();
$collection
->
string
(
'mykey3'
)
->
index
();
});
});
...
@@ -77,8 +72,7 @@ class SchemaTest extends TestCase {
...
@@ -77,8 +72,7 @@ class SchemaTest extends TestCase {
public
function
testPrimary
()
public
function
testPrimary
()
{
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
{
$collection
->
string
(
'mykey'
,
100
)
->
primary
();
$collection
->
string
(
'mykey'
,
100
)
->
primary
();
});
});
...
@@ -88,8 +82,7 @@ class SchemaTest extends TestCase {
...
@@ -88,8 +82,7 @@ class SchemaTest extends TestCase {
public
function
testUnique
()
public
function
testUnique
()
{
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
{
$collection
->
unique
(
'uniquekey'
);
$collection
->
unique
(
'uniquekey'
);
});
});
...
@@ -99,8 +92,7 @@ class SchemaTest extends TestCase {
...
@@ -99,8 +92,7 @@ class SchemaTest extends TestCase {
public
function
testDropIndex
()
public
function
testDropIndex
()
{
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
{
$collection
->
unique
(
'uniquekey'
);
$collection
->
unique
(
'uniquekey'
);
$collection
->
dropIndex
(
'uniquekey'
);
$collection
->
dropIndex
(
'uniquekey'
);
});
});
...
@@ -108,8 +100,7 @@ class SchemaTest extends TestCase {
...
@@ -108,8 +100,7 @@ class SchemaTest extends TestCase {
$index
=
$this
->
getIndex
(
'newcollection'
,
'uniquekey'
);
$index
=
$this
->
getIndex
(
'newcollection'
,
'uniquekey'
);
$this
->
assertEquals
(
null
,
$index
);
$this
->
assertEquals
(
null
,
$index
);
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
{
$collection
->
unique
(
'uniquekey'
);
$collection
->
unique
(
'uniquekey'
);
$collection
->
dropIndex
([
'uniquekey'
]);
$collection
->
dropIndex
([
'uniquekey'
]);
});
});
...
@@ -120,8 +111,7 @@ class SchemaTest extends TestCase {
...
@@ -120,8 +111,7 @@ class SchemaTest extends TestCase {
public
function
testBackground
()
public
function
testBackground
()
{
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
{
$collection
->
background
(
'backgroundkey'
);
$collection
->
background
(
'backgroundkey'
);
});
});
...
@@ -131,8 +121,7 @@ class SchemaTest extends TestCase {
...
@@ -131,8 +121,7 @@ class SchemaTest extends TestCase {
public
function
testSparse
()
public
function
testSparse
()
{
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
{
$collection
->
sparse
(
'sparsekey'
);
$collection
->
sparse
(
'sparsekey'
);
});
});
...
@@ -142,8 +131,7 @@ class SchemaTest extends TestCase {
...
@@ -142,8 +131,7 @@ class SchemaTest extends TestCase {
public
function
testExpire
()
public
function
testExpire
()
{
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
{
$collection
->
expire
(
'expirekey'
,
60
);
$collection
->
expire
(
'expirekey'
,
60
);
});
});
...
@@ -153,13 +141,11 @@ class SchemaTest extends TestCase {
...
@@ -153,13 +141,11 @@ class SchemaTest extends TestCase {
public
function
testSoftDeletes
()
public
function
testSoftDeletes
()
{
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
{
$collection
->
softDeletes
();
$collection
->
softDeletes
();
});
});
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
{
$collection
->
string
(
'email'
)
->
nullable
()
->
index
();
$collection
->
string
(
'email'
)
->
nullable
()
->
index
();
});
});
...
@@ -169,8 +155,7 @@ class SchemaTest extends TestCase {
...
@@ -169,8 +155,7 @@ class SchemaTest extends TestCase {
public
function
testFluent
()
public
function
testFluent
()
{
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
{
$collection
->
string
(
'email'
)
->
index
();
$collection
->
string
(
'email'
)
->
index
();
$collection
->
string
(
'token'
)
->
index
();
$collection
->
string
(
'token'
)
->
index
();
$collection
->
timestamp
(
'created_at'
);
$collection
->
timestamp
(
'created_at'
);
...
@@ -185,8 +170,7 @@ class SchemaTest extends TestCase {
...
@@ -185,8 +170,7 @@ class SchemaTest extends TestCase {
public
function
testDummies
()
public
function
testDummies
()
{
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
{
$collection
->
boolean
(
'activated'
)
->
default
(
0
);
$collection
->
boolean
(
'activated'
)
->
default
(
0
);
$collection
->
integer
(
'user_id'
)
->
unsigned
();
$collection
->
integer
(
'user_id'
)
->
unsigned
();
});
});
...
@@ -196,12 +180,12 @@ class SchemaTest extends TestCase {
...
@@ -196,12 +180,12 @@ class SchemaTest extends TestCase {
{
{
$collection
=
DB
::
getCollection
(
$collection
);
$collection
=
DB
::
getCollection
(
$collection
);
foreach
(
$collection
->
listIndexes
()
as
$index
)
foreach
(
$collection
->
listIndexes
()
as
$index
)
{
{
if
(
isset
(
$index
[
'key'
][
$name
]))
{
if
(
isset
(
$index
[
'key'
][
$name
]))
return
$index
;
return
$index
;
}
}
}
return
false
;
return
false
;
}
}
}
}
tests/SeederTest.php
View file @
76858f3c
<?php
<?php
class
SeederTest
extends
TestCase
{
class
SeederTest
extends
TestCase
{
public
function
tearDown
()
public
function
tearDown
()
{
{
...
@@ -23,5 +24,4 @@ class SeederTest extends TestCase {
...
@@ -23,5 +24,4 @@ class SeederTest extends TestCase {
$user
=
User
::
where
(
'name'
,
'John Doe'
)
->
first
();
$user
=
User
::
where
(
'name'
,
'John Doe'
)
->
first
();
$this
->
assertTrue
(
$user
->
seed
);
$this
->
assertTrue
(
$user
->
seed
);
}
}
}
}
tests/TestCase.php
View file @
76858f3c
<?php
<?php
class
TestCase
extends
Orchestra\Testbench\TestCase
{
class
TestCase
extends
Orchestra\Testbench\TestCase
{
/**
/**
* Get package providers.
* Get package providers.
...
@@ -36,5 +37,4 @@ class TestCase extends Orchestra\Testbench\TestCase {
...
@@ -36,5 +37,4 @@ class TestCase extends Orchestra\Testbench\TestCase {
$app
[
'config'
]
->
set
(
'auth.model'
,
'User'
);
$app
[
'config'
]
->
set
(
'auth.model'
,
'User'
);
$app
[
'config'
]
->
set
(
'cache.driver'
,
'array'
);
$app
[
'config'
]
->
set
(
'cache.driver'
,
'array'
);
}
}
}
}
tests/ValidationTest.php
View file @
76858f3c
<?php
<?php
class
ValidationTest
extends
TestCase
{
class
ValidationTest
extends
TestCase
{
public
function
tearDown
()
public
function
tearDown
()
{
{
...
@@ -23,5 +24,4 @@ class ValidationTest extends TestCase {
...
@@ -23,5 +24,4 @@ class ValidationTest extends TestCase {
);
);
$this
->
assertTrue
(
$validator
->
fails
());
$this
->
assertTrue
(
$validator
->
fails
());
}
}
}
}
tests/models/Address.php
View file @
76858f3c
...
@@ -2,7 +2,8 @@
...
@@ -2,7 +2,8 @@
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
class
Address
extends
Eloquent
{
class
Address
extends
Eloquent
{
protected
static
$unguarded
=
true
;
protected
static
$unguarded
=
true
;
...
@@ -10,5 +11,4 @@ class Address extends Eloquent {
...
@@ -10,5 +11,4 @@ class Address extends Eloquent {
{
{
return
$this
->
embedsMany
(
'Address'
);
return
$this
->
embedsMany
(
'Address'
);
}
}
}
}
tests/models/Book.php
View file @
76858f3c
...
@@ -2,7 +2,8 @@
...
@@ -2,7 +2,8 @@
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
class
Book
extends
Eloquent
{
class
Book
extends
Eloquent
{
protected
$collection
=
'books'
;
protected
$collection
=
'books'
;
protected
static
$unguarded
=
true
;
protected
static
$unguarded
=
true
;
...
...
tests/models/Client.php
View file @
76858f3c
...
@@ -2,7 +2,8 @@
...
@@ -2,7 +2,8 @@
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
class
Client
extends
Eloquent
{
class
Client
extends
Eloquent
{
protected
$collection
=
'clients'
;
protected
$collection
=
'clients'
;
protected
static
$unguarded
=
true
;
protected
static
$unguarded
=
true
;
...
...
tests/models/Group.php
View file @
76858f3c
...
@@ -2,7 +2,8 @@
...
@@ -2,7 +2,8 @@
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
class
Group
extends
Eloquent
{
class
Group
extends
Eloquent
{
protected
$collection
=
'groups'
;
protected
$collection
=
'groups'
;
protected
static
$unguarded
=
true
;
protected
static
$unguarded
=
true
;
...
...
tests/models/Item.php
View file @
76858f3c
...
@@ -2,7 +2,8 @@
...
@@ -2,7 +2,8 @@
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
class
Item
extends
Eloquent
{
class
Item
extends
Eloquent
{
protected
$collection
=
'items'
;
protected
$collection
=
'items'
;
protected
static
$unguarded
=
true
;
protected
static
$unguarded
=
true
;
...
@@ -16,5 +17,4 @@ class Item extends Eloquent {
...
@@ -16,5 +17,4 @@ class Item extends Eloquent {
{
{
return
$query
->
where
(
'type'
,
'sharp'
);
return
$query
->
where
(
'type'
,
'sharp'
);
}
}
}
}
tests/models/MysqlBook.php
View file @
76858f3c
...
@@ -3,7 +3,8 @@
...
@@ -3,7 +3,8 @@
use
Illuminate\Support\Facades\Schema
;
use
Illuminate\Support\Facades\Schema
;
use
Jenssegers\Mongodb\Eloquent\HybridRelations
;
use
Jenssegers\Mongodb\Eloquent\HybridRelations
;
class
MysqlBook
extends
Eloquent
{
class
MysqlBook
extends
Eloquent
{
use
HybridRelations
;
use
HybridRelations
;
...
@@ -24,15 +25,12 @@ class MysqlBook extends Eloquent {
...
@@ -24,15 +25,12 @@ class MysqlBook extends Eloquent {
{
{
$schema
=
Schema
::
connection
(
'mysql'
);
$schema
=
Schema
::
connection
(
'mysql'
);
if
(
!
$schema
->
hasTable
(
'books'
))
if
(
!
$schema
->
hasTable
(
'books'
))
{
{
Schema
::
connection
(
'mysql'
)
->
create
(
'books'
,
function
(
$table
)
{
Schema
::
connection
(
'mysql'
)
->
create
(
'books'
,
function
(
$table
)
{
$table
->
string
(
'title'
);
$table
->
string
(
'title'
);
$table
->
string
(
'author_id'
);
$table
->
string
(
'author_id'
);
$table
->
timestamps
();
$table
->
timestamps
();
});
});
}
}
}
}
}
}
tests/models/MysqlRole.php
View file @
76858f3c
...
@@ -3,7 +3,8 @@
...
@@ -3,7 +3,8 @@
use
Illuminate\Support\Facades\Schema
;
use
Illuminate\Support\Facades\Schema
;
use
Jenssegers\Mongodb\Eloquent\HybridRelations
;
use
Jenssegers\Mongodb\Eloquent\HybridRelations
;
class
MysqlRole
extends
Eloquent
{
class
MysqlRole
extends
Eloquent
{
use
HybridRelations
;
use
HybridRelations
;
...
@@ -28,15 +29,12 @@ class MysqlRole extends Eloquent {
...
@@ -28,15 +29,12 @@ class MysqlRole extends Eloquent {
{
{
$schema
=
Schema
::
connection
(
'mysql'
);
$schema
=
Schema
::
connection
(
'mysql'
);
if
(
!
$schema
->
hasTable
(
'roles'
))
if
(
!
$schema
->
hasTable
(
'roles'
))
{
{
Schema
::
connection
(
'mysql'
)
->
create
(
'roles'
,
function
(
$table
)
{
Schema
::
connection
(
'mysql'
)
->
create
(
'roles'
,
function
(
$table
)
{
$table
->
string
(
'type'
);
$table
->
string
(
'type'
);
$table
->
string
(
'user_id'
);
$table
->
string
(
'user_id'
);
$table
->
timestamps
();
$table
->
timestamps
();
});
});
}
}
}
}
}
}
tests/models/MysqlUser.php
View file @
76858f3c
...
@@ -3,7 +3,8 @@
...
@@ -3,7 +3,8 @@
use
Illuminate\Support\Facades\Schema
;
use
Illuminate\Support\Facades\Schema
;
use
Jenssegers\Mongodb\Eloquent\HybridRelations
;
use
Jenssegers\Mongodb\Eloquent\HybridRelations
;
class
MysqlUser
extends
Eloquent
{
class
MysqlUser
extends
Eloquent
{
use
HybridRelations
;
use
HybridRelations
;
...
@@ -28,15 +29,12 @@ class MysqlUser extends Eloquent {
...
@@ -28,15 +29,12 @@ class MysqlUser extends Eloquent {
{
{
$schema
=
Schema
::
connection
(
'mysql'
);
$schema
=
Schema
::
connection
(
'mysql'
);
if
(
!
$schema
->
hasTable
(
'users'
))
if
(
!
$schema
->
hasTable
(
'users'
))
{
{
Schema
::
connection
(
'mysql'
)
->
create
(
'users'
,
function
(
$table
)
{
Schema
::
connection
(
'mysql'
)
->
create
(
'users'
,
function
(
$table
)
{
$table
->
increments
(
'id'
);
$table
->
increments
(
'id'
);
$table
->
string
(
'name'
);
$table
->
string
(
'name'
);
$table
->
timestamps
();
$table
->
timestamps
();
});
});
}
}
}
}
}
}
tests/models/Photo.php
View file @
76858f3c
...
@@ -2,7 +2,8 @@
...
@@ -2,7 +2,8 @@
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
class
Photo
extends
Eloquent
{
class
Photo
extends
Eloquent
{
protected
$collection
=
'photos'
;
protected
$collection
=
'photos'
;
protected
static
$unguarded
=
true
;
protected
static
$unguarded
=
true
;
...
@@ -11,5 +12,4 @@ class Photo extends Eloquent {
...
@@ -11,5 +12,4 @@ class Photo extends Eloquent {
{
{
return
$this
->
morphTo
();
return
$this
->
morphTo
();
}
}
}
}
tests/models/Role.php
View file @
76858f3c
...
@@ -2,7 +2,8 @@
...
@@ -2,7 +2,8 @@
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
class
Role
extends
Eloquent
{
class
Role
extends
Eloquent
{
protected
$collection
=
'roles'
;
protected
$collection
=
'roles'
;
protected
static
$unguarded
=
true
;
protected
static
$unguarded
=
true
;
...
@@ -16,5 +17,4 @@ class Role extends Eloquent {
...
@@ -16,5 +17,4 @@ class Role extends Eloquent {
{
{
return
$this
->
belongsTo
(
'MysqlUser'
);
return
$this
->
belongsTo
(
'MysqlUser'
);
}
}
}
}
tests/models/Soft.php
View file @
76858f3c
...
@@ -3,12 +3,12 @@
...
@@ -3,12 +3,12 @@
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
use
Jenssegers\Mongodb\Eloquent\SoftDeletes
;
use
Jenssegers\Mongodb\Eloquent\SoftDeletes
;
class
Soft
extends
Eloquent
{
class
Soft
extends
Eloquent
{
use
SoftDeletes
;
use
SoftDeletes
;
protected
$collection
=
'soft'
;
protected
$collection
=
'soft'
;
protected
static
$unguarded
=
true
;
protected
static
$unguarded
=
true
;
protected
$dates
=
[
'deleted_at'
];
protected
$dates
=
[
'deleted_at'
];
}
}
tests/models/User.php
View file @
76858f3c
...
@@ -6,7 +6,8 @@ use Illuminate\Auth\Passwords\CanResetPassword;
...
@@ -6,7 +6,8 @@ use Illuminate\Auth\Passwords\CanResetPassword;
use
Illuminate\Contracts\Auth\Authenticatable
as
AuthenticatableContract
;
use
Illuminate\Contracts\Auth\Authenticatable
as
AuthenticatableContract
;
use
Illuminate\Contracts\Auth\CanResetPassword
as
CanResetPasswordContract
;
use
Illuminate\Contracts\Auth\CanResetPassword
as
CanResetPasswordContract
;
class
User
extends
Eloquent
implements
AuthenticatableContract
,
CanResetPasswordContract
{
class
User
extends
Eloquent
implements
AuthenticatableContract
,
CanResetPasswordContract
{
use
Authenticatable
,
CanResetPassword
;
use
Authenticatable
,
CanResetPassword
;
...
...
tests/seeds/DatabaseSeeder.php
View file @
76858f3c
...
@@ -2,7 +2,8 @@
...
@@ -2,7 +2,8 @@
use
Illuminate\Database\Seeder
;
use
Illuminate\Database\Seeder
;
class
DatabaseSeeder
extends
Seeder
{
class
DatabaseSeeder
extends
Seeder
{
/**
/**
* Run the database seeds.
* Run the database seeds.
...
...
tests/seeds/UserTableSeeder.php
View file @
76858f3c
...
@@ -3,7 +3,8 @@
...
@@ -3,7 +3,8 @@
use
Illuminate\Database\Seeder
;
use
Illuminate\Database\Seeder
;
use
Illuminate\Support\Facades\DB
;
use
Illuminate\Support\Facades\DB
;
class
UserTableSeeder
extends
Seeder
{
class
UserTableSeeder
extends
Seeder
{
public
function
run
()
public
function
run
()
{
{
...
...
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