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
27a1c63e
Commit
27a1c63e
authored
Nov 29, 2013
by
Klimov Paul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Mongo "_id" processing advanced.
parent
3fd6d95a
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
2 deletions
+52
-2
ActiveRecord.php
extensions/mongo/ActiveRecord.php
+26
-0
Collection.php
extensions/mongo/Collection.php
+10
-0
ActiveRelationTest.php
tests/unit/extensions/mongo/ActiveRelationTest.php
+3
-2
QueryRunTest.php
tests/unit/extensions/mongo/QueryRunTest.php
+13
-0
No files found.
extensions/mongo/ActiveRecord.php
View file @
27a1c63e
...
@@ -1157,4 +1157,29 @@ abstract class ActiveRecord extends Model
...
@@ -1157,4 +1157,29 @@ abstract class ActiveRecord extends Model
throw
new
InvalidParamException
(
get_class
(
$this
)
.
' has no relation named "'
.
$name
.
'".'
,
0
,
$e
);
throw
new
InvalidParamException
(
get_class
(
$this
)
.
' has no relation named "'
.
$name
.
'".'
,
0
,
$e
);
}
}
}
}
/**
* Sets the element at the specified offset.
* This method is required by the SPL interface `ArrayAccess`.
* It is implicitly called when you use something like `$model[$offset] = $item;`.
* @param integer $offset the offset to set element
* @param mixed $item the element value
* @throws \Exception on failure
*/
public
function
offsetSet
(
$offset
,
$item
)
{
// Bypass relation owner restriction to 'yii\db\ActiveRecord' at [[yii\db\ActiveRelationTrait::findWith()]]:
try
{
$relation
=
$this
->
getRelation
(
$offset
);
if
(
is_object
(
$relation
))
{
$this
->
populateRelation
(
$offset
,
$item
);
return
;
}
}
catch
(
InvalidParamException
$e
)
{
// shut down exception : has getter, but not relation
}
catch
(
UnknownMethodException
$e
)
{
throw
$e
->
getPrevious
();
}
parent
::
offsetSet
(
$offset
,
$item
);
}
}
}
\ No newline at end of file
extensions/mongo/Collection.php
View file @
27a1c63e
...
@@ -267,8 +267,18 @@ class Collection extends Object
...
@@ -267,8 +267,18 @@ class Collection extends Object
$key
=
$this
->
normalizeConditionKeyword
(
$key
);
$key
=
$this
->
normalizeConditionKeyword
(
$key
);
if
(
strncmp
(
'$'
,
$key
,
1
)
!==
0
&&
is_array
(
$actualValue
)
&&
array_key_exists
(
0
,
$actualValue
))
{
if
(
strncmp
(
'$'
,
$key
,
1
)
!==
0
&&
is_array
(
$actualValue
)
&&
array_key_exists
(
0
,
$actualValue
))
{
// shortcut for IN condition
// shortcut for IN condition
if
(
$key
==
'_id'
)
{
foreach
(
$actualValue
as
&
$actualValuePart
)
{
if
(
!
is_object
(
$actualValuePart
))
{
$actualValuePart
=
new
\MongoId
(
$actualValuePart
);
}
}
}
$result
[
$key
][
'$in'
]
=
$actualValue
;
$result
[
$key
][
'$in'
]
=
$actualValue
;
}
else
{
}
else
{
if
(
$key
==
'_id'
&&
!
is_object
(
$actualValue
))
{
$actualValue
=
new
\MongoId
(
$actualValue
);
}
$result
[
$key
]
=
$actualValue
;
$result
[
$key
]
=
$actualValue
;
}
}
}
}
...
...
tests/unit/extensions/mongo/ActiveRelationTest.php
View file @
27a1c63e
...
@@ -77,7 +77,7 @@ class ActiveRelationTest extends MongoTestCase
...
@@ -77,7 +77,7 @@ class ActiveRelationTest extends MongoTestCase
$this
->
assertEquals
(
10
,
count
(
$orders
));
$this
->
assertEquals
(
10
,
count
(
$orders
));
$this
->
assertTrue
(
$orders
[
0
]
->
isRelationPopulated
(
'customer'
));
$this
->
assertTrue
(
$orders
[
0
]
->
isRelationPopulated
(
'customer'
));
$this
->
assertTrue
(
$orders
[
1
]
->
isRelationPopulated
(
'customer'
));
$this
->
assertTrue
(
$orders
[
1
]
->
isRelationPopulated
(
'customer'
));
$this
->
assertTrue
(
$orders
[
0
]
->
index
instanceof
ArticleIndex
);
$this
->
assertTrue
(
$orders
[
0
]
->
customer
instanceof
Customer
);
$this
->
assertTrue
(
$orders
[
1
]
->
index
instanceof
ArticleIndex
);
$this
->
assertTrue
(
$orders
[
1
]
->
customer
instanceof
Customer
);
}
}
}
}
\ No newline at end of file
tests/unit/extensions/mongo/QueryRunTest.php
View file @
27a1c63e
...
@@ -105,4 +105,16 @@ class QueryRunTest extends MongoTestCase
...
@@ -105,4 +105,16 @@ class QueryRunTest extends MongoTestCase
->
all
(
$connection
);
->
all
(
$connection
);
$this
->
assertEquals
(
'name9'
,
$rows
[
0
][
'name'
]);
$this
->
assertEquals
(
'name9'
,
$rows
[
0
][
'name'
]);
}
}
public
function
testMatchPlainId
()
{
$connection
=
$this
->
getConnection
();
$query
=
new
Query
;
$row
=
$query
->
from
(
'customer'
)
->
one
(
$connection
);
$query
=
new
Query
;
$rows
=
$query
->
from
(
'customer'
)
->
where
([
'_id'
=>
$row
[
'_id'
]
->
__toString
()])
->
all
(
$connection
);
$this
->
assertEquals
(
1
,
count
(
$rows
));
}
}
}
\ No newline at end of file
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