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
683a46d9
Commit
683a46d9
authored
Feb 25, 2014
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test for deeply nested relation
close #2543
parent
4ac784cd
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
0 deletions
+28
-0
Customer.php
tests/unit/data/ar/Customer.php
+12
-0
ActiveRecordTest.php
tests/unit/framework/db/ActiveRecordTest.php
+16
-0
No files found.
tests/unit/data/ar/Customer.php
View file @
683a46d9
<?php
namespace
yiiunit\data\ar
;
use
yii\db\ActiveQuery
;
use
yiiunit\framework\db\ActiveRecordTest
;
/**
...
...
@@ -34,6 +35,17 @@ class Customer extends ActiveRecord
return
$this
->
hasMany
(
Order
::
className
(),
[
'customer_id'
=>
'id'
])
->
inverseOf
(
'customer2'
)
->
orderBy
(
'id'
);
}
// deeply nested table relation
public
function
getOrderItems
()
{
/** @var ActiveQuery $rel */
$rel
=
$this
->
hasMany
(
Item
::
className
(),
[
'id'
=>
'item_id'
]);
return
$rel
->
viaTable
(
'tbl_order_item'
,
[
'order_id'
=>
'id'
],
function
(
$q
)
{
/** @var ActiveQuery $q */
$q
->
viaTable
(
'tbl_order'
,
[
'customer_id'
=>
'id'
]);
})
->
orderBy
(
'id'
);
}
public
function
afterSave
(
$insert
)
{
ActiveRecordTest
::
$afterSaveInsert
=
$insert
;
...
...
tests/unit/framework/db/ActiveRecordTest.php
View file @
683a46d9
...
...
@@ -131,6 +131,22 @@ class ActiveRecordTest extends DatabaseTestCase
$this
->
assertEquals
(
2
,
$order
[
'books'
][
1
][
'id'
]);
}
// deeply nested table relation
public
function
testDeeplyNestedTableRelation
()
{
/** @var Customer $customer */
$customer
=
$this
->
callCustomerFind
(
1
);
$this
->
assertNotNull
(
$customer
);
$items
=
$customer
->
orderItems
;
$this
->
assertEquals
(
2
,
count
(
$items
));
$this
->
assertInstanceOf
(
Item
::
className
(),
$items
[
0
]);
$this
->
assertInstanceOf
(
Item
::
className
(),
$items
[
1
]);
$this
->
assertEquals
(
1
,
$items
[
0
]
->
id
);
$this
->
assertEquals
(
2
,
$items
[
1
]
->
id
);
}
public
function
testStoreNull
()
{
$record
=
new
NullValues
();
...
...
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