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
3058f37a
Commit
3058f37a
authored
Aug 09, 2014
by
Jens Segers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename getParent to getParentRelation and added more tests for soft deletion
parent
d5283da2
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
41 additions
and
36 deletions
+41
-36
Builder.php
src/Jenssegers/Mongodb/Eloquent/Builder.php
+6
-6
Model.php
src/Jenssegers/Mongodb/Model.php
+5
-5
EmbedsOneOrMany.php
src/Jenssegers/Mongodb/Relations/EmbedsOneOrMany.php
+6
-6
ModelTest.php
tests/ModelTest.php
+20
-16
Soft.php
tests/models/Soft.php
+4
-3
No files found.
src/Jenssegers/Mongodb/Eloquent/Builder.php
View file @
3058f37a
...
...
@@ -26,7 +26,7 @@ class Builder extends EloquentBuilder {
{
// Intercept operations on embedded models and delegate logic
// to the parent relation instance.
if
(
$relation
=
$this
->
model
->
getParent
())
if
(
$relation
=
$this
->
model
->
getParent
Relation
())
{
$relation
->
performUpdate
(
$this
->
model
,
$values
);
...
...
@@ -46,7 +46,7 @@ class Builder extends EloquentBuilder {
{
// Intercept operations on embedded models and delegate logic
// to the parent relation instance.
if
(
$relation
=
$this
->
model
->
getParent
())
if
(
$relation
=
$this
->
model
->
getParent
Relation
())
{
$relation
->
performInsert
(
$this
->
model
,
$values
);
...
...
@@ -67,7 +67,7 @@ class Builder extends EloquentBuilder {
{
// Intercept operations on embedded models and delegate logic
// to the parent relation instance.
if
(
$relation
=
$this
->
model
->
getParent
())
if
(
$relation
=
$this
->
model
->
getParent
Relation
())
{
$relation
->
performInsert
(
$this
->
model
,
$values
);
...
...
@@ -86,7 +86,7 @@ class Builder extends EloquentBuilder {
{
// Intercept operations on embedded models and delegate logic
// to the parent relation instance.
if
(
$relation
=
$this
->
model
->
getParent
())
if
(
$relation
=
$this
->
model
->
getParent
Relation
())
{
$relation
->
performDelete
(
$this
->
model
);
...
...
@@ -108,7 +108,7 @@ class Builder extends EloquentBuilder {
{
// Intercept operations on embedded models and delegate logic
// to the parent relation instance.
if
(
$relation
=
$this
->
model
->
getParent
())
if
(
$relation
=
$this
->
model
->
getParent
Relation
())
{
$value
=
$this
->
model
->
{
$column
};
...
...
@@ -138,7 +138,7 @@ class Builder extends EloquentBuilder {
{
// Intercept operations on embedded models and delegate logic
// to the parent relation instance.
if
(
$relation
=
$this
->
model
->
getParent
())
if
(
$relation
=
$this
->
model
->
getParent
Relation
())
{
$value
=
$this
->
model
->
{
$column
};
...
...
src/Jenssegers/Mongodb/Model.php
View file @
3058f37a
...
...
@@ -35,7 +35,7 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
*
* @var Relation
*/
protected
$parent
;
protected
$parent
Relation
;
/**
* The connection resolver instance.
...
...
@@ -470,9 +470,9 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
*
* @param Relation $relation
*/
public
function
setParent
(
Relation
$relation
)
public
function
setParent
Relation
(
Relation
$relation
)
{
$this
->
parent
=
$relation
;
$this
->
parent
Relation
=
$relation
;
}
/**
...
...
@@ -480,9 +480,9 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
*
* @return Relation
*/
public
function
getParent
()
public
function
getParent
Relation
()
{
return
$this
->
parent
;
return
$this
->
parent
Relation
;
}
/**
...
...
src/Jenssegers/Mongodb/Relations/EmbedsOneOrMany.php
View file @
3058f37a
...
...
@@ -94,7 +94,7 @@ abstract class EmbedsOneOrMany extends Relation {
{
foreach
(
$models
as
$model
)
{
$model
->
setParent
(
$this
);
$model
->
setParent
Relation
(
$this
);
$model
->
setRelation
(
$relation
,
$this
->
related
->
newCollection
());
}
...
...
@@ -116,7 +116,7 @@ abstract class EmbedsOneOrMany extends Relation {
{
$results
=
$model
->
$relation
()
->
getResults
();
$model
->
setParent
(
$this
);
$model
->
setParent
Relation
(
$this
);
$model
->
setRelation
(
$relation
,
$results
);
}
...
...
@@ -152,7 +152,7 @@ abstract class EmbedsOneOrMany extends Relation {
*/
public
function
save
(
Model
$model
)
{
$model
->
setParent
(
$this
);
$model
->
setParent
Relation
(
$this
);
return
$model
->
save
()
?
$model
:
false
;
}
...
...
@@ -183,7 +183,7 @@ abstract class EmbedsOneOrMany extends Relation {
// on the models. Otherwise, some of these attributes will not get set.
$instance
=
$this
->
related
->
newInstance
(
$attributes
);
$instance
->
setParent
(
$this
);
$instance
->
setParent
Relation
(
$this
);
$instance
->
save
();
...
...
@@ -310,7 +310,7 @@ abstract class EmbedsOneOrMany extends Relation {
$model
=
$this
->
related
->
newFromBuilder
((
array
)
$attributes
);
$model
->
setParent
(
$this
);
$model
->
setParent
Relation
(
$this
);
$model
->
setRelation
(
$this
->
foreignKey
,
$this
->
parent
);
...
...
@@ -327,7 +327,7 @@ abstract class EmbedsOneOrMany extends Relation {
*/
protected
function
getParentRelation
()
{
return
$this
->
parent
->
getParent
();
return
$this
->
parent
->
getParent
Relation
();
}
/**
...
...
tests/ModelTest.php
View file @
3058f37a
...
...
@@ -267,29 +267,33 @@ class ModelTest extends TestCase {
public
function
testSoftDelete
()
{
$user
=
new
Soft
;
$user
->
name
=
'Softy'
;
$user
->
save
();
Soft
::
create
(
array
(
'name'
=>
'John Doe'
));
Soft
::
create
(
array
(
'name'
=>
'Jane Doe'
));
$this
->
assertEquals
(
2
,
Soft
::
count
());
$user
=
Soft
::
where
(
'name'
,
'John Doe'
)
->
first
();
$this
->
assertEquals
(
true
,
$user
->
exists
);
$this
->
assertEquals
(
false
,
$user
->
trashed
());
$this
->
assertNull
(
$user
->
deleted_at
);
$user
->
delete
();
$this
->
assertEquals
(
true
,
$user
->
trashed
());
$this
->
assertNotNull
(
$user
->
deleted_at
);
$check
=
Soft
::
find
(
$user
->
_id
);
$this
->
assertEquals
(
null
,
$check
);
$all
=
Soft
::
get
();
$this
->
assertEquals
(
0
,
$all
->
count
());
$user
=
Soft
::
where
(
'name'
,
'John Doe'
)
->
first
();
$this
->
assertNull
(
$user
);
$
all
=
Soft
::
withTrashed
()
->
get
(
);
$this
->
assertEquals
(
1
,
$all
->
count
());
$
this
->
assertEquals
(
1
,
Soft
::
count
()
);
$this
->
assertEquals
(
2
,
Soft
::
withTrashed
()
->
count
());
$check
=
$all
[
0
];
$this
->
assertInstanceOf
(
'Carbon\Carbon'
,
$check
->
deleted_at
);
$this
->
assertEquals
(
true
,
$check
->
trashed
());
$user
=
Soft
::
withTrashed
()
->
where
(
'name'
,
'John Doe'
)
->
first
();
$this
->
assertNotNull
(
$user
);
$this
->
assertInstanceOf
(
'Carbon\Carbon'
,
$user
->
deleted_at
);
$this
->
assertEquals
(
true
,
$user
->
trashed
());
$check
->
restore
();
$all
=
Soft
::
get
();
$this
->
assertEquals
(
1
,
$all
->
count
());
$user
->
restore
();
$this
->
assertEquals
(
2
,
Soft
::
count
());
}
public
function
testPrimaryKey
()
...
...
tests/models/Soft.php
View file @
3058f37a
...
...
@@ -5,9 +5,10 @@ use Jenssegers\Mongodb\Eloquent\SoftDeletingTrait;
class
Soft
extends
Eloquent
{
use
SoftDeletingTrait
;
use
SoftDeletingTrait
;
protected
$collection
=
'soft'
;
protected
$dates
=
array
(
'deleted_at'
);
protected
$collection
=
'soft'
;
protected
static
$unguarded
=
true
;
protected
$dates
=
array
(
'deleted_at'
);
}
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