diff --git a/core/dbobjectsearch.class.php b/core/dbobjectsearch.class.php index 9e769e1ea..5bf9cb8dd 100644 --- a/core/dbobjectsearch.class.php +++ b/core/dbobjectsearch.class.php @@ -1036,7 +1036,7 @@ class DBObjectSearch extends DBSearch public function Filter($sClassAlias, DBSearch $oFilter) { // If the conditions are the correct ones for Intersect - if (($this->GetFirstJoinedClass() == $oFilter->GetFirstJoinedClass())) + if (MetaModel::IsParentClass($oFilter->GetFirstJoinedClass(),$this->GetFirstJoinedClass())) { return $this->Intersect($oFilter); } diff --git a/test/core/DBSearchIntersectTest.php b/test/core/DBSearchIntersectTest.php index 9a5be882d..dd0b3e149 100644 --- a/test/core/DBSearchIntersectTest.php +++ b/test/core/DBSearchIntersectTest.php @@ -52,6 +52,20 @@ class DBSearchIntersectTest extends ItopDataTestCase { $aTests = array(); + $aTests['Union filtered by parent class'] = array( + 'left' => "SELECT ApplicationSolution UNION SELECT BusinessProcess", + 'right' => "SELECT FunctionalCI WHERE org_id = 3", + 'alias' => "ApplicationSolution", + 'result' => "SELECT `ApplicationSolution` FROM ApplicationSolution AS `ApplicationSolution` WHERE (`ApplicationSolution`.`org_id` = 3) UNION SELECT `BusinessProcess` FROM BusinessProcess AS `BusinessProcess` WHERE (`BusinessProcess`.`org_id` = 3)"); + + +// Bug to fix +// $aTests['Test union #2902'] = array( +// 'left' => "SELECT `L-1` FROM ServiceFamily AS `L-1` WHERE 1", +// 'right' => "SELECT `sf` FROM ServiceFamily AS `sf` JOIN Service AS `s` ON `s`.servicefamily_id = `sf`.id JOIN lnkCustomerContractToService AS `l1` ON `l1`.service_id = `s`.id JOIN CustomerContract AS `cc` ON `l1`.customercontract_id = `cc`.id WHERE (`cc`.`org_id` = 3) UNION SELECT `sf` FROM ServiceFamily AS `sf` JOIN Service AS `s` ON `s`.servicefamily_id = `sf`.id JOIN lnkCustomerContractToService AS `l1` ON `l1`.service_id = `s`.id JOIN CustomerContract AS `cc` ON `l1`.customercontract_id = `cc`.id JOIN Organization AS `child` ON `cc`.org_id = `child`.id JOIN Organization AS `root` ON `child`.parent_id BELOW `root`.id WHERE (`root`.`id` = 3)", +// 'alias' => "L-1", +// 'result' => "SELECT `L-1` FROM ServiceFamily AS `L-1` JOIN Service AS `s` ON `s`.servicefamily_id = `L-1`.id JOIN lnkCustomerContractToService AS `l1` ON `l1`.service_id = `s`.id JOIN CustomerContract AS `cc` ON `l1`.customercontract_id = `cc`.id WHERE (`cc`.`org_id` = 3) UNION SELECT `L-1` FROM ServiceFamily AS `L-1` JOIN Service AS `s` ON `s`.servicefamily_id = `L-1`.id JOIN lnkCustomerContractToService AS `l1` ON `l1`.service_id = `s`.id JOIN CustomerContract AS `cc` ON `l1`.customercontract_id = `cc`.id JOIN Organization AS `child` ON `cc`.org_id = `child`.id JOIN Organization AS `root` ON `child`.parent_id BELOW `root`.id WHERE (`root`.`id` = 3)"); + $aTests['Multiple selected classes inverted'] = array( 'left' => "SELECT `L`, `P` FROM Person AS `P` JOIN Location AS `L` ON `P`.location_id = `L`.id WHERE 1", 'right' => "SELECT Person WHERE org_id = 3", @@ -116,19 +130,19 @@ class DBSearchIntersectTest extends ItopDataTestCase 'left' => "SELECT `U` FROM UserRequest AS `U` WHERE `U`.agent_id = 3", 'right' => "SELECT `Ticket` WHERE org_id = 3", 'alias' => "U", - 'result' => "SELECT `U` FROM UserRequest AS `U` WHERE (((`U`.`agent_id` = 3) AND (`U`.`org_id` = 3)) AND ((`U`.`agent_id` = 3) AND (`U`.`org_id` = 3)))"); + 'result' => "SELECT `U` FROM UserRequest AS `U` WHERE ((`U`.`agent_id` = 3) AND (`U`.`org_id` = 3))"); $aTests['Test Subclass and join'] = array( 'left' => "SELECT `UserRequest` FROM UserRequest AS `UserRequest` JOIN Person AS `P` ON `UserRequest`.agent_id = `P`.id WHERE `UserRequest`.agent_id = 3", 'right' => "SELECT `Ticket` WHERE org_id = 3", 'alias' => "UserRequest", - 'result' => "SELECT `UserRequest` FROM UserRequest AS `UserRequest` JOIN Person AS `P` ON `UserRequest`.agent_id = `P`.id WHERE (((`UserRequest`.`agent_id` = 3) AND (`UserRequest`.`org_id` = 3)) AND ((`UserRequest`.`agent_id` = 3) AND (`UserRequest`.`org_id` = 3)))"); + 'result' => "SELECT `UserRequest` FROM UserRequest AS `UserRequest` JOIN Person AS `P` ON `UserRequest`.agent_id = `P`.id WHERE ((`UserRequest`.`agent_id` = 3) AND (`UserRequest`.`org_id` = 3))"); $aTests['Test Subclass and union'] = array( 'left' => "SELECT `U` FROM UserRequest AS `U` WHERE `U`.agent_id = 3 UNION SELECT `T` FROM Ticket AS `T` WHERE `T`.agent_id = 3 ", 'right' => "SELECT `Ticket` WHERE org_id = 3", 'alias' => "U", - 'result' => "SELECT `U` FROM UserRequest AS `U` WHERE (((`U`.`agent_id` = 3) AND (`U`.`org_id` = 3)) AND ((`U`.`agent_id` = 3) AND (`U`.`org_id` = 3))) UNION SELECT `T` FROM Ticket AS `T` WHERE ((`T`.`agent_id` = 3) AND (`T`.`org_id` = 3))"); + 'result' => "SELECT `U` FROM UserRequest AS `U` WHERE ((`U`.`agent_id` = 3) AND (`U`.`org_id` = 3)) UNION SELECT `T` FROM Ticket AS `T` WHERE ((`T`.`agent_id` = 3) AND (`T`.`org_id` = 3))");