Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
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
PSDI Army
yii2
Commits
15c8935d
Commit
15c8935d
authored
Oct 09, 2014
by
Klimov Paul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed `yii\mongodb\ActiveRecord` unable to fetch 'hasMany' referred by array of `\MongoId`
parent
85a9887a
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
64 additions
and
6 deletions
+64
-6
CHANGELOG.md
extensions/mongodb/CHANGELOG.md
+1
-0
ActiveRelationTrait.php
framework/db/ActiveRelationTrait.php
+3
-0
CustomerOrder.php
tests/unit/data/ar/mongodb/CustomerOrder.php
+6
-1
Item.php
tests/unit/data/ar/mongodb/Item.php
+21
-0
ActiveRelationTest.php
tests/unit/extensions/mongodb/ActiveRelationTest.php
+33
-5
No files found.
extensions/mongodb/CHANGELOG.md
View file @
15c8935d
...
...
@@ -5,6 +5,7 @@ Yii Framework 2 mongodb extension Change Log
-----------------------
-
Bug #5303: Fixed
`yii\mongodb\Collection`
unable to fetch default database name from DSN with parameters (klimov-paul)
-
Bug #5411: Fixed
`yii\mongodb\ActiveRecord`
unable to fetch 'hasMany' referred by array of
`\MongoId`
(klimov-paul)
2.0.0-rc September 27, 2014
...
...
framework/db/ActiveRelationTrait.php
View file @
15c8935d
...
...
@@ -252,6 +252,9 @@ trait ActiveRelationTrait
if
(
$this
->
multiple
&&
count
(
$link
)
==
1
&&
is_array
(
$keys
=
$primaryModel
[
reset
(
$link
)]))
{
$value
=
[];
foreach
(
$keys
as
$key
)
{
if
(
!
is_scalar
(
$key
))
{
$key
=
serialize
(
$key
);
}
if
(
isset
(
$buckets
[
$key
]))
{
if
(
$this
->
indexBy
!==
null
)
{
// if indexBy is set, array_merge will cause renumbering of numeric array
...
...
tests/unit/data/ar/mongodb/CustomerOrder.php
View file @
15c8935d
...
...
@@ -15,7 +15,7 @@ class CustomerOrder extends ActiveRecord
'_id'
,
'number'
,
'customer_id'
,
'items'
,
'item
_id
s'
,
];
}
...
...
@@ -23,4 +23,9 @@ class CustomerOrder extends ActiveRecord
{
return
$this
->
hasOne
(
Customer
::
className
(),
[
'_id'
=>
'customer_id'
]);
}
public
function
getItems
()
{
return
$this
->
hasMany
(
Item
::
className
(),
[
'_id'
=>
'item_ids'
]);
}
}
tests/unit/data/ar/mongodb/Item.php
0 → 100644
View file @
15c8935d
<?php
namespace
yiiunit\data\ar\mongodb
;
class
Item
extends
ActiveRecord
{
public
static
function
collectionName
()
{
return
'item'
;
}
public
function
attributes
()
{
return
[
'_id'
,
'name'
,
'price'
,
];
}
}
\ No newline at end of file
tests/unit/extensions/mongodb/ActiveRelationTest.php
View file @
15c8935d
...
...
@@ -30,8 +30,6 @@ class ActiveRelationTest extends MongoDbTestCase
*/
protected
function
setUpTestRows
()
{
$customerCollection
=
$this
->
getConnection
()
->
getCollection
(
'customer'
);
$customers
=
[];
for
(
$i
=
1
;
$i
<=
5
;
$i
++
)
{
$customers
[]
=
[
...
...
@@ -41,20 +39,39 @@ class ActiveRelationTest extends MongoDbTestCase
'status'
=>
$i
,
];
}
$customerCollection
->
batchInsert
(
$customers
);
$customerCollection
=
$this
->
getConnection
()
->
getCollection
(
'customer'
);
$customers
=
$customerCollection
->
batchInsert
(
$customers
);
$items
=
[];
for
(
$i
=
1
;
$i
<=
10
;
$i
++
)
{
$items
[]
=
[
'name'
=>
'name'
.
$i
,
'price'
=>
$i
,
];
}
$itemCollection
=
$this
->
getConnection
()
->
getCollection
(
'item'
);
$items
=
$itemCollection
->
batchInsert
(
$items
);
$customerOrderCollection
=
$this
->
getConnection
()
->
getCollection
(
'customer_order'
);
$customerOrders
=
[];
foreach
(
$customers
as
$customer
)
{
foreach
(
$customers
as
$
i
=>
$
customer
)
{
$customerOrders
[]
=
[
'customer_id'
=>
$customer
[
'_id'
],
'number'
=>
$customer
[
'status'
],
'item_ids'
=>
[
$items
[
$i
][
'_id'
],
$items
[
$i
+
5
][
'_id'
],
],
];
$customerOrders
[]
=
[
'customer_id'
=>
$customer
[
'_id'
],
'number'
=>
$customer
[
'status'
]
+
100
,
'item_ids'
=>
[
$items
[
$i
][
'_id'
],
$items
[
$i
+
5
][
'_id'
],
],
];
}
$customerOrderCollection
=
$this
->
getConnection
()
->
getCollection
(
'customer_order'
);
$customerOrderCollection
->
batchInsert
(
$customerOrders
);
}
...
...
@@ -83,4 +100,15 @@ class ActiveRelationTest extends MongoDbTestCase
$this
->
assertTrue
(
$orders
[
1
]
->
customer
instanceof
Customer
);
$this
->
assertEquals
((
string
)
$orders
[
1
]
->
customer
->
_id
,
(
string
)
$orders
[
1
]
->
customer_id
);
}
/**
* @see https://github.com/yiisoft/yii2/issues/5411
*
* @depends testFindEager
*/
public
function
testFindEagerHasManyByArrayKey
()
{
$order
=
CustomerOrder
::
find
()
->
where
([
'number'
=>
1
])
->
with
(
'items'
)
->
one
();
$this
->
assertNotEmpty
(
$order
->
items
);
}
}
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