Skip to content

Commit f5e170d

Browse files
EdaCZdg
authored andcommitted
tests: Added for bug 170 (#232)
1 parent 3e9159e commit f5e170d

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/**
4+
* Test: bug 170
5+
* @dataProvider? ../../databases.ini mysql
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
use Tester\Assert;
11+
12+
require __DIR__ . '/../../connect.inc.php';
13+
14+
Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../../files/{$driverName}-bug170.sql");
15+
16+
Assert::noError(function () use ($context) {
17+
// this bug is about picking the right foreign key to specified table regardless FKs definition order
18+
$context->table('Operator1')->where('country.id')->count();
19+
$context->table('Operator2')->where('country.id')->count();
20+
});
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
DROP DATABASE IF EXISTS nette_test;
2+
CREATE DATABASE nette_test;
3+
USE nette_test;
4+
5+
CREATE TABLE `Country` (
6+
`id` int(4) unsigned NOT NULL AUTO_INCREMENT,
7+
PRIMARY KEY (`id`)
8+
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci;
9+
10+
CREATE TABLE `Region` (
11+
`order` int(1) unsigned NOT NULL,
12+
`countryId` int(4) unsigned NOT NULL,
13+
PRIMARY KEY (`countryId`, `order`),
14+
CONSTRAINT `Region_ibfk_2` FOREIGN KEY (`countryId`) REFERENCES `Country` (`id`)
15+
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci;
16+
17+
CREATE TABLE `Operator1` (
18+
`id` int(4) unsigned NOT NULL AUTO_INCREMENT,
19+
`countryId` int(4) unsigned NOT NULL,
20+
`regionOrder` int(1) unsigned NOT NULL,
21+
PRIMARY KEY (`id`),
22+
CONSTRAINT `Operator_ibfk_1` FOREIGN KEY (`countryId`, `regionOrder`) REFERENCES `Region` (`countryId`, `order`),
23+
CONSTRAINT `Operator_ibfk_2` FOREIGN KEY (`countryId`) REFERENCES `Country` (`id`)
24+
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci;
25+
26+
CREATE TABLE `Operator2` (
27+
`id` int(4) unsigned NOT NULL AUTO_INCREMENT,
28+
`countryId` int(4) unsigned NOT NULL,
29+
`regionOrder` int(1) unsigned NOT NULL,
30+
PRIMARY KEY (`id`),
31+
CONSTRAINT `Operator2_ibfk_1` FOREIGN KEY (`countryId`) REFERENCES `Country` (`id`),
32+
CONSTRAINT `Operator2_ibfk_2` FOREIGN KEY (`countryId`, `regionOrder`) REFERENCES `Region` (`countryId`, `order`)
33+
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci;
34+
35+
-- NOTE: Order of foreign keys to tables Region and Country is reversed in Operator2 table compared to Operator1 table

0 commit comments

Comments
 (0)