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
b0568612
Commit
b0568612
authored
Dec 03, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #1402: AR eager loading has problem when asArray() is used together with viaTable().
parent
ef51c7b2
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
2 deletions
+10
-2
ActiveQueryTrait.php
framework/yii/db/ActiveQueryTrait.php
+1
-1
ActiveRelationTrait.php
framework/yii/db/ActiveRelationTrait.php
+5
-1
ActiveRecordTestTrait.php
tests/unit/framework/ar/ActiveRecordTestTrait.php
+4
-0
No files found.
framework/yii/db/ActiveQueryTrait.php
View file @
b0568612
...
@@ -146,7 +146,7 @@ trait ActiveQueryTrait
...
@@ -146,7 +146,7 @@ trait ActiveQueryTrait
* Finds records corresponding to one or multiple relations and populates them into the primary models.
* Finds records corresponding to one or multiple relations and populates them into the primary models.
* @param array $with a list of relations that this query should be performed with. Please
* @param array $with a list of relations that this query should be performed with. Please
* refer to [[with()]] for details about specifying this parameter.
* refer to [[with()]] for details about specifying this parameter.
* @param
ActiveRecord[] $models the primary models
* @param
array $models the primary models (can be either AR instances or arrays)
*/
*/
public
function
findWith
(
$with
,
&
$models
)
public
function
findWith
(
$with
,
&
$models
)
{
{
...
...
framework/yii/db/ActiveRelationTrait.php
View file @
b0568612
...
@@ -236,7 +236,7 @@ trait ActiveRelationTrait
...
@@ -236,7 +236,7 @@ trait ActiveRelationTrait
}
}
/**
/**
* @param
ActiveRecord[] $primaryModel
s
* @param
array $primaryModels either array of AR instances or array
s
* @return array
* @return array
*/
*/
private
function
findPivotRows
(
$primaryModels
)
private
function
findPivotRows
(
$primaryModels
)
...
@@ -247,6 +247,10 @@ trait ActiveRelationTrait
...
@@ -247,6 +247,10 @@ trait ActiveRelationTrait
$this
->
filterByModels
(
$primaryModels
);
$this
->
filterByModels
(
$primaryModels
);
/** @var ActiveRecord $primaryModel */
/** @var ActiveRecord $primaryModel */
$primaryModel
=
reset
(
$primaryModels
);
$primaryModel
=
reset
(
$primaryModels
);
if
(
!
$primaryModel
instanceof
ActiveRecordInterface
)
{
// when primaryModels are array of arrays (asArray case)
$primaryModel
=
new
$this
->
modelClass
;
}
return
$this
->
asArray
()
->
all
(
$primaryModel
->
getDb
());
return
$this
->
asArray
()
->
all
(
$primaryModel
->
getDb
());
}
}
}
}
tests/unit/framework/ar/ActiveRecordTestTrait.php
View file @
b0568612
...
@@ -411,6 +411,10 @@ trait ActiveRecordTestTrait
...
@@ -411,6 +411,10 @@ trait ActiveRecordTestTrait
$this
->
assertTrue
(
$customer
->
isRelationPopulated
(
'orders'
));
$this
->
assertTrue
(
$customer
->
isRelationPopulated
(
'orders'
));
$this
->
assertEquals
(
1
,
count
(
$customer
->
orders
));
$this
->
assertEquals
(
1
,
count
(
$customer
->
orders
));
$this
->
assertEquals
(
1
,
count
(
$customer
->
populatedRelations
));
$this
->
assertEquals
(
1
,
count
(
$customer
->
populatedRelations
));
// https://github.com/yiisoft/yii2/issues/1402
$orders
=
$this
->
callOrderFind
()
->
with
(
'books'
)
->
asArray
()
->
all
();
$this
->
assertEquals
(
3
,
count
(
$orders
));
}
}
public
function
testFindLazyVia
()
public
function
testFindLazyVia
()
...
...
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