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
b23b59ee
Commit
b23b59ee
authored
Mar 04, 2014
by
Jens Segers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Using underscore attribute for embedsMany, check #138
parent
128eb7b5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
10 deletions
+11
-10
Model.php
src/Jenssegers/Mongodb/Model.php
+10
-10
RelationsTest.php
tests/RelationsTest.php
+1
-0
No files found.
src/Jenssegers/Mongodb/Model.php
View file @
b23b59ee
...
@@ -57,16 +57,6 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
...
@@ -57,16 +57,6 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
*/
*/
protected
function
embedsMany
(
$related
,
$localKey
=
null
,
$foreignKey
=
null
,
$relation
=
null
)
protected
function
embedsMany
(
$related
,
$localKey
=
null
,
$foreignKey
=
null
,
$relation
=
null
)
{
{
if
(
is_null
(
$localKey
))
{
$localKey
=
snake_case
(
str_plural
(
$related
))
.
'_ids'
;
}
if
(
is_null
(
$foreignKey
))
{
$foreignKey
=
snake_case
(
class_basename
(
$this
));
}
// 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.
...
@@ -77,6 +67,16 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
...
@@ -77,6 +67,16 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
$relation
=
$caller
[
'function'
];
$relation
=
$caller
[
'function'
];
}
}
if
(
is_null
(
$localKey
))
{
$localKey
=
'_'
.
$relation
;
}
if
(
is_null
(
$foreignKey
))
{
$foreignKey
=
snake_case
(
class_basename
(
$this
));
}
$query
=
$this
->
newQuery
();
$query
=
$this
->
newQuery
();
$instance
=
new
$related
;
$instance
=
new
$related
;
...
...
tests/RelationsTest.php
View file @
b23b59ee
...
@@ -289,6 +289,7 @@ class RelationsTest extends PHPUnit_Framework_TestCase {
...
@@ -289,6 +289,7 @@ class RelationsTest extends PHPUnit_Framework_TestCase {
$address
=
new
Address
(
array
(
'city'
=>
'London'
));
$address
=
new
Address
(
array
(
'city'
=>
'London'
));
$address
=
$user
->
addresses
()
->
save
(
$address
);
$address
=
$user
->
addresses
()
->
save
(
$address
);
$this
->
assertNotNull
(
$user
->
_addresses
);
$this
->
assertEquals
(
array
(
'London'
),
$user
->
addresses
->
lists
(
'city'
));
$this
->
assertEquals
(
array
(
'London'
),
$user
->
addresses
->
lists
(
'city'
));
$this
->
assertInstanceOf
(
'DateTime'
,
$address
->
created_at
);
$this
->
assertInstanceOf
(
'DateTime'
,
$address
->
created_at
);
$this
->
assertInstanceOf
(
'DateTime'
,
$address
->
updated_at
);
$this
->
assertInstanceOf
(
'DateTime'
,
$address
->
updated_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