From db03f4f408a91c654fbf055deb5004e6e8ab305f Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Mon, 17 Aug 2020 13:49:20 +0300 Subject: [PATCH] fixes --- .../ORM/QueryComposer/BaseQueryComposer.php | 2 + .../Espo/ORM/Repository/RDBRepository.php | 11 ++-- tests/integration/Espo/ORM/MapperTest.php | 63 +++++-------------- 3 files changed, 22 insertions(+), 54 deletions(-) diff --git a/application/Espo/ORM/QueryComposer/BaseQueryComposer.php b/application/Espo/ORM/QueryComposer/BaseQueryComposer.php index b8275052e6..dc6b1ac89f 100644 --- a/application/Espo/ORM/QueryComposer/BaseQueryComposer.php +++ b/application/Espo/ORM/QueryComposer/BaseQueryComposer.php @@ -1895,6 +1895,8 @@ abstract class BaseQueryComposer implements QueryComposer return $this->convertMatchExpression($entity, $value); } + $noCustomWhere = $noCustomWhere ?? $params['noCustomWhere'] ?? false; + if (is_int($field)) { $field = 'AND'; } diff --git a/application/Espo/ORM/Repository/RDBRepository.php b/application/Espo/ORM/Repository/RDBRepository.php index 3889284029..57f8f342c7 100644 --- a/application/Espo/ORM/Repository/RDBRepository.php +++ b/application/Espo/ORM/Repository/RDBRepository.php @@ -460,12 +460,12 @@ class RDBRepository extends Repository } if ($foreign instanceof Entity) { - $id = $foreign->id; + $result = $this->getMapper()->relate($entity, $relationName, $foreign, $data); } else { $id = $foreign; - } - $result = $this->getMapper()->relateById($entity, $relationName, $id, $data); + $result = $this->getMapper()->relateById($entity, $relationName, $id, $data); + } } if ($result) { @@ -511,12 +511,11 @@ class RDBRepository extends Repository $result = $this->$methodName($entity, $foreign); } else { if ($foreign instanceof Entity) { - $id = $foreign->id; + $result = $this->getMapper()->unrelate($entity, $relationName, $foreign); } else { $id = $foreign; + $result = $this->getMapper()->unrelateById($entity, $relationName, $id); } - - $result = $this->getMapper()->unrelateById($entity, $relationName, $id); } if ($result) { diff --git a/tests/integration/Espo/ORM/MapperTest.php b/tests/integration/Espo/ORM/MapperTest.php index 5776ecc5ae..440d912e44 100644 --- a/tests/integration/Espo/ORM/MapperTest.php +++ b/tests/integration/Espo/ORM/MapperTest.php @@ -129,19 +129,19 @@ class MapperTest extends \tests\integration\Core\BaseTestCase $isRelated = $em->getRepository('Lead')->isRelated($l1, 'createdAccount', $a1); $this->assertTrue($isRelated); - $isRelated = $em->getRepository('Lead')->isRelated($a1, 'originalLead', $l1); + $isRelated = $em->getRepository('Account')->isRelated($a1, 'originalLead', $l1); $this->assertTrue($isRelated); $isRelated = $em->getRepository('Lead')->isRelated($l1, 'createdAccount', $a2); $this->assertFalse($isRelated); - $isRelated = $em->getRepository('Lead')->isRelated($a2, 'originalLead', $l1); + $isRelated = $em->getRepository('Account')->isRelated($a2, 'originalLead', $l1); $this->assertFalse($isRelated); $em->getRepository('Lead')->relate($l1, 'createdAccount', $a2); - $isRelated = $em->getRepository('Lead')->isRelated($a2, 'originalLead', $l1); + $isRelated = $em->getRepository('Account')->isRelated($a2, 'originalLead', $l1); $this->assertTrue($isRelated); $isRelated = $em->getRepository('Lead')->isRelated($l1, 'createdAccount', $a2); @@ -150,7 +150,7 @@ class MapperTest extends \tests\integration\Core\BaseTestCase $isRelated = $em->getRepository('Lead')->isRelated($l1, 'createdAccount', $a1); $this->assertFalse($isRelated); - $isRelated = $em->getRepository('Lead')->isRelated($a1, 'originalLead', $l1); + $isRelated = $em->getRepository('Account')->isRelated($a1, 'originalLead', $l1); $this->assertFalse($isRelated); $c = $em->getRepository('Lead')->where(['createdAccountId' => $a1->id])->count(); @@ -179,24 +179,24 @@ class MapperTest extends \tests\integration\Core\BaseTestCase 'lastName' => '2', ]); - $em->getRepository('Lead')->relate($a1, 'originalLead', $l1); + $em->getRepository('Account')->relate($a1, 'originalLead', $l1); $isRelated = $em->getRepository('Lead')->isRelated($l1, 'createdAccount', $a1); $this->assertTrue($isRelated); - $isRelated = $em->getRepository('Lead')->isRelated($a1, 'originalLead', $l1); + $isRelated = $em->getRepository('Account')->isRelated($a1, 'originalLead', $l1); $this->assertTrue($isRelated); $isRelated = $em->getRepository('Lead')->isRelated($l1, 'createdAccount', $a2); $this->assertFalse($isRelated); - $isRelated = $em->getRepository('Lead')->isRelated($a2, 'originalLead', $l1); + $isRelated = $em->getRepository('Account')->isRelated($a2, 'originalLead', $l1); $this->assertFalse($isRelated); - $em->getRepository('Lead')->relate($a2, 'originalLead', $l1); + $em->getRepository('Account')->relate($a2, 'originalLead', $l1); - $isRelated = $em->getRepository('Lead')->isRelated($a2, 'originalLead', $l1); + $isRelated = $em->getRepository('Account')->isRelated($a2, 'originalLead', $l1); $this->assertTrue($isRelated); $isRelated = $em->getRepository('Lead')->isRelated($l1, 'createdAccount', $a2); @@ -205,7 +205,7 @@ class MapperTest extends \tests\integration\Core\BaseTestCase $isRelated = $em->getRepository('Lead')->isRelated($l1, 'createdAccount', $a1); $this->assertFalse($isRelated); - $isRelated = $em->getRepository('Lead')->isRelated($a1, 'originalLead', $l1); + $isRelated = $em->getRepository('Account')->isRelated($a1, 'originalLead', $l1); $this->assertFalse($isRelated); $c = $em->getRepository('Lead')->where(['createdAccountId' => $a1->id])->count(); @@ -239,19 +239,19 @@ class MapperTest extends \tests\integration\Core\BaseTestCase $isRelated = $em->getRepository('Lead')->isRelated($l1, 'createdAccount', $a1); $this->assertTrue($isRelated); - $isRelated = $em->getRepository('Lead')->isRelated($a1, 'originalLead', $l1); + $isRelated = $em->getRepository('Account')->isRelated($a1, 'originalLead', $l1); $this->assertTrue($isRelated); $isRelated = $em->getRepository('Lead')->isRelated($l2, 'createdAccount', $a1); $this->assertFalse($isRelated); - $isRelated = $em->getRepository('Lead')->isRelated($a1, 'originalLead', $l2); + $isRelated = $em->getRepository('Account')->isRelated($a1, 'originalLead', $l2); $this->assertFalse($isRelated); $em->getRepository('Lead')->relate($l2, 'createdAccount', $a1); - $isRelated = $em->getRepository('Lead')->isRelated($a1, 'originalLead', $l2); + $isRelated = $em->getRepository('Account')->isRelated($a1, 'originalLead', $l2); $this->assertTrue($isRelated); $isRelated = $em->getRepository('Lead')->isRelated($l2, 'createdAccount', $a1); @@ -262,7 +262,7 @@ class MapperTest extends \tests\integration\Core\BaseTestCase $isRelated = $em->getRepository('Lead')->isRelated($l1, 'createdAccount', $a1); $this->assertFalse($isRelated); - $isRelated = $em->getRepository('Lead')->isRelated($a1, 'originalLead', $l1); + $isRelated = $em->getRepository('Account')->isRelated($a1, 'originalLead', $l1); $this->assertFalse($isRelated); $c = $em->getRepository('Lead')->where(['createdAccountId' => $a1->id])->count(); @@ -295,44 +295,11 @@ class MapperTest extends \tests\integration\Core\BaseTestCase $this->assertFalse($isRelated); $em->getRepository('Lead')->relate($l1, 'createdAccount', $a1); - $em->getRepository('Lead')->unrelate($a1, 'originalLead', $l1); + $em->getRepository('Account')->unrelate($a1, 'originalLead', $l1); $l1 = $em->getEntity('Lead', $l1->id); $isRelated = $em->getRepository('Lead')->isRelated($l1, 'createdAccount', $a1); $this->assertFalse($isRelated); } - - public function testMassDeleteFromDb1() - { - $app = $this->createApplication(); - $em = $app->getContainer()->get('entityManager'); - $mapper = $em->getMapper('RDB'); - - $a1 = $em->createEntity('Account', [ - 'name' => '1', - ]); - $a2 = $em->createEntity('Account', [ - 'name' => '2', - ]); - - $count = $mapper->massDeleteFromDb('Account', [ - 'name' => '1', - ]); - - $this->assertEquals(1, $count); - - $a1 = $em->getEntity('Account', $a1->id); - $this->assertNull($a1); - - $a2 = $em->getEntity('Account', $a2->id); - $this->assertNotNull($a2); - - - $count = $mapper->massDeleteFromDb('Account', [ - 'name' => '3', - ]); - - $this->assertEquals(0, $count); - } }