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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Rotua Panjaitan
yii2
Commits
dc01411b
Commit
dc01411b
authored
Jan 07, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #1791
parent
73e0e6ab
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
17 deletions
+36
-17
ActiveQuery.php
framework/yii/db/ActiveQuery.php
+1
-14
ActiveQueryTrait.php
framework/yii/db/ActiveQueryTrait.php
+25
-3
ActiveRecordTestTrait.php
tests/unit/framework/ar/ActiveRecordTestTrait.php
+10
-0
No files found.
framework/yii/db/ActiveQuery.php
View file @
dc01411b
...
...
@@ -247,20 +247,7 @@ class ActiveQuery extends Query implements ActiveQueryInterface
$with
=
[];
}
if
(
!
empty
(
$with
))
{
$this
->
with
=
[];
foreach
(
$with
as
$name
=>
$value
)
{
if
(
is_integer
(
$name
))
{
// repeating relation is fine as ActiveQueryTrait::normalizeRelations() handle it well
$this
->
with
[]
=
$value
;
}
elseif
(
!
isset
(
$this
->
with
[
$name
]))
{
// with() takes precedence over joinWith() when both specify the same relation with callback
$this
->
with
[
$name
]
=
$value
;
}
}
}
return
$this
;
return
$this
->
with
(
$with
);
}
/**
...
...
framework/yii/db/ActiveQueryTrait.php
View file @
dc01411b
...
...
@@ -93,15 +93,37 @@ trait ActiveQueryTrait
* ])->all();
* ~~~
*
* You can call `with()` multiple times. Each call will add relations to the existing ones.
* For example, the following two statements are equivalent:
*
* ~~~
* Customer::find()->with('orders', 'country')->all();
* Customer::find()->with('orders')->with('country')->all();
* ~~~
*
* @return static the query object itself
*/
public
function
with
()
{
$
this
->
with
=
func_get_args
();
if
(
isset
(
$
this
->
with
[
0
])
&&
is_array
(
$this
->
with
[
0
]))
{
$with
=
func_get_args
();
if
(
isset
(
$
with
[
0
])
&&
is_array
(
$
with
[
0
]))
{
// the parameter is given as an array
$this
->
with
=
$this
->
with
[
0
];
$with
=
$with
[
0
];
}
if
(
empty
(
$this
->
with
))
{
$this
->
with
=
$with
;
}
elseif
(
!
empty
(
$with
))
{
foreach
(
$with
as
$name
=>
$value
)
{
if
(
is_integer
(
$name
))
{
// repeating relation is fine as normalizeRelations() handle it well
$this
->
with
[]
=
$value
;
}
else
{
$this
->
with
[
$name
]
=
$value
;
}
}
}
return
$this
;
}
...
...
tests/unit/framework/ar/ActiveRecordTestTrait.php
View file @
dc01411b
...
...
@@ -422,6 +422,16 @@ trait ActiveRecordTestTrait
$this
->
assertTrue
(
$customer
->
isRelationPopulated
(
'orders'
));
$this
->
assertEquals
(
1
,
count
(
$customer
->
orders
));
$this
->
assertEquals
(
1
,
count
(
$customer
->
relatedRecords
));
// multiple with() calls
$orders
=
$this
->
callOrderFind
()
->
with
(
'customer'
,
'items'
)
->
all
();
$this
->
assertEquals
(
3
,
count
(
$orders
));
$this
->
assertTrue
(
$orders
[
0
]
->
isRelationPopulated
(
'customer'
));
$this
->
assertTrue
(
$orders
[
0
]
->
isRelationPopulated
(
'items'
));
$orders
=
$this
->
callOrderFind
()
->
with
(
'customer'
)
->
with
(
'items'
)
->
all
();
$this
->
assertEquals
(
3
,
count
(
$orders
));
$this
->
assertTrue
(
$orders
[
0
]
->
isRelationPopulated
(
'customer'
));
$this
->
assertTrue
(
$orders
[
0
]
->
isRelationPopulated
(
'items'
));
}
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