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
00249c1f
Commit
00249c1f
authored
Aug 09, 2014
by
Jens Segers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #236
parent
c29d5301
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
39 additions
and
3 deletions
+39
-3
Model.php
src/Jenssegers/Mongodb/Model.php
+13
-2
HasMany.php
src/Jenssegers/Mongodb/Relations/HasMany.php
+10
-0
HasOne.php
src/Jenssegers/Mongodb/Relations/HasOne.php
+10
-0
RelationsTest.php
tests/RelationsTest.php
+5
-0
Client.php
tests/models/Client.php
+1
-1
No files found.
src/Jenssegers/Mongodb/Model.php
View file @
00249c1f
...
@@ -222,7 +222,7 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
...
@@ -222,7 +222,7 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
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
pos
(
$key
,
'.'
)
!==
false
)
if
(
str
_contains
(
$key
,
'.'
)
)
{
{
$attributes
=
array_dot
(
$this
->
attributes
);
$attributes
=
array_dot
(
$this
->
attributes
);
...
@@ -274,7 +274,7 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
...
@@ -274,7 +274,7 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
return
$this
->
attributes
[
$key
];
return
$this
->
attributes
[
$key
];
}
}
else
if
(
strpos
(
$key
,
'.'
)
!==
false
)
else
if
(
str_contains
(
$key
,
'.'
)
)
{
{
$attributes
=
array_dot
(
$this
->
attributes
);
$attributes
=
array_dot
(
$this
->
attributes
);
...
@@ -302,6 +302,17 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
...
@@ -302,6 +302,17 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
$value
=
$builder
->
convertKey
(
$value
);
$value
=
$builder
->
convertKey
(
$value
);
}
}
// Support keys in dot notation.
elseif
(
str_contains
(
$key
,
'.'
))
{
if
(
in_array
(
$key
,
$this
->
getDates
())
&&
$value
)
{
$value
=
$this
->
fromDateTime
(
$value
);
}
array_set
(
$this
->
attributes
,
$key
,
$value
);
return
;
}
parent
::
setAttribute
(
$key
,
$value
);
parent
::
setAttribute
(
$key
,
$value
);
}
}
...
...
src/Jenssegers/Mongodb/Relations/HasMany.php
View file @
00249c1f
...
@@ -20,4 +20,14 @@ class HasMany extends EloquentHasMany {
...
@@ -20,4 +20,14 @@ class HasMany extends EloquentHasMany {
return
$query
->
select
(
$this
->
getHasCompareKey
())
->
where
(
$this
->
getHasCompareKey
(),
'exists'
,
true
);
return
$query
->
select
(
$this
->
getHasCompareKey
())
->
where
(
$this
->
getHasCompareKey
(),
'exists'
,
true
);
}
}
/**
* Get the plain foreign key.
*
* @return string
*/
public
function
getPlainForeignKey
()
{
return
$this
->
getForeignKey
();
}
}
}
src/Jenssegers/Mongodb/Relations/HasOne.php
View file @
00249c1f
...
@@ -20,4 +20,14 @@ class HasOne extends EloquentHasOne {
...
@@ -20,4 +20,14 @@ class HasOne extends EloquentHasOne {
return
$query
->
select
(
$this
->
getHasCompareKey
())
->
where
(
$this
->
getHasCompareKey
(),
'exists'
,
true
);
return
$query
->
select
(
$this
->
getHasCompareKey
())
->
where
(
$this
->
getHasCompareKey
(),
'exists'
,
true
);
}
}
/**
* Get the plain foreign key.
*
* @return string
*/
public
function
getPlainForeignKey
()
{
return
$this
->
getForeignKey
();
}
}
}
tests/RelationsTest.php
View file @
00249c1f
...
@@ -131,6 +131,7 @@ class RelationsTest extends TestCase {
...
@@ -131,6 +131,7 @@ class RelationsTest extends TestCase {
$items
=
$user
->
items
;
$items
=
$user
->
items
;
$this
->
assertEquals
(
1
,
count
(
$items
));
$this
->
assertEquals
(
1
,
count
(
$items
));
$this
->
assertInstanceOf
(
'Item'
,
$items
[
0
]);
$this
->
assertInstanceOf
(
'Item'
,
$items
[
0
]);
$this
->
assertEquals
(
$user
->
_id
,
$items
[
0
]
->
user_id
);
// Has one
// Has one
$user
=
User
::
create
(
array
(
'name'
=>
'John Doe'
));
$user
=
User
::
create
(
array
(
'name'
=>
'John Doe'
));
...
@@ -141,6 +142,7 @@ class RelationsTest extends TestCase {
...
@@ -141,6 +142,7 @@ class RelationsTest extends TestCase {
$role
=
$user
->
role
;
$role
=
$user
->
role
;
$this
->
assertInstanceOf
(
'Role'
,
$role
);
$this
->
assertInstanceOf
(
'Role'
,
$role
);
$this
->
assertEquals
(
'admin'
,
$role
->
type
);
$this
->
assertEquals
(
'admin'
,
$role
->
type
);
$this
->
assertEquals
(
$user
->
_id
,
$role
->
user_id
);
}
}
public
function
testBelongsToMany
()
public
function
testBelongsToMany
()
...
@@ -415,6 +417,9 @@ class RelationsTest extends TestCase {
...
@@ -415,6 +417,9 @@ class RelationsTest extends TestCase {
$address
=
$client
->
addresses
->
first
();
$address
=
$client
->
addresses
->
first
();
$this
->
assertEquals
(
'Paris'
,
$address
->
data
[
'city'
]);
$this
->
assertEquals
(
'Paris'
,
$address
->
data
[
'city'
]);
$client
=
Client
::
with
(
'addresses'
)
->
first
();
$this
->
assertEquals
(
'Paris'
,
$client
->
addresses
->
first
()
->
data
[
'city'
]);
}
}
public
function
testDoubleSaveOneToMany
()
public
function
testDoubleSaveOneToMany
()
...
...
tests/models/Client.php
View file @
00249c1f
...
@@ -19,6 +19,6 @@ class Client extends Eloquent {
...
@@ -19,6 +19,6 @@ class Client extends Eloquent {
public
function
addresses
()
public
function
addresses
()
{
{
return
$this
->
hasMany
(
'Address'
,
'data.
client_id'
,
'data.address
_id'
);
return
$this
->
hasMany
(
'Address'
,
'data.
address_id'
,
'data.client
_id'
);
}
}
}
}
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