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
1b4d894c
Commit
1b4d894c
authored
Oct 03, 2014
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
created test for #5341
parent
79815252
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
0 deletions
+38
-0
Category.php
tests/unit/data/ar/Category.php
+10
-0
ActiveRecordTest.php
tests/unit/framework/db/ActiveRecordTest.php
+28
-0
No files found.
tests/unit/data/ar/Category.php
View file @
1b4d894c
...
...
@@ -30,4 +30,14 @@ class Category extends ActiveRecord
return
$this
->
hasMany
(
Item
::
className
(),
[
'category_id'
=>
'id'
])
->
onCondition
([
'item.id'
=>
[
1
,
2
,
3
]]);
}
public
function
getOrderItems
()
{
return
$this
->
hasMany
(
OrderItem
::
className
(),
[
'item_id'
=>
'id'
])
->
via
(
'items'
);
}
public
function
getOrders
()
{
return
$this
->
hasMany
(
Order
::
className
(),
[
'id'
=>
'order_id'
])
->
via
(
'orderItems'
);
}
}
tests/unit/framework/db/ActiveRecordTest.php
View file @
1b4d894c
...
...
@@ -176,6 +176,34 @@ class ActiveRecordTest extends DatabaseTestCase
$this
->
assertEquals
(
2
,
$items
[
1
]
->
id
);
}
/**
* https://github.com/yiisoft/yii2/issues/5341
*
* Issue: Plan 1 -- * Account * -- * User
* Our Tests: Category 1 -- * Item * -- * Order
*/
public
function
testDeeplyNestedTableRelation2
()
{
/* @var $category Category */
$category
=
Category
::
findOne
(
1
);
$this
->
assertNotNull
(
$category
);
$orders
=
$category
->
orders
;
$this
->
assertEquals
(
2
,
count
(
$orders
));
$this
->
assertInstanceOf
(
Order
::
className
(),
$orders
[
0
]);
$this
->
assertInstanceOf
(
Order
::
className
(),
$orders
[
1
]);
$ids
=
[
$orders
[
0
]
->
id
,
$orders
[
1
]
->
id
];
sort
(
$ids
);
$this
->
assertEquals
([
1
,
3
],
$ids
);
$category
=
Category
::
findOne
(
2
);
$this
->
assertNotNull
(
$category
);
$orders
=
$category
->
orders
;
$this
->
assertEquals
(
1
,
count
(
$orders
));
$this
->
assertInstanceOf
(
Order
::
className
(),
$orders
[
0
]);
$this
->
assertEquals
(
2
,
$orders
[
0
]
->
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