diff --git a/application/Espo/Entities/Attachment.php b/application/Espo/Entities/Attachment.php index db204b727a..3032da4fd4 100644 --- a/application/Espo/Entities/Attachment.php +++ b/application/Espo/Entities/Attachment.php @@ -189,16 +189,28 @@ class Attachment extends Entity return $this; } - public function setParent(?LinkParent $parent): self + public function setParent(LinkParent|Entity|null $parent): self { - $this->setValueObject('parent', $parent); + if ($parent instanceof LinkParent) { + $this->setValueObject('parent', $parent); + + return $this; + } + + $this->relations->set('parent', $parent); return $this; } - public function setRelated(?LinkParent $related): self + public function setRelated(LinkParent|Entity|null $related): self { - $this->setValueObject('related', $related); + if ($related instanceof LinkParent) { + $this->setValueObject('related', $related); + + return $this; + } + + $this->relations->set('related', $related); return $this; } diff --git a/application/Espo/Entities/Email.php b/application/Espo/Entities/Email.php index 76c0fc9c9d..e7ec883c82 100644 --- a/application/Espo/Entities/Email.php +++ b/application/Espo/Entities/Email.php @@ -632,9 +632,15 @@ class Email extends Entity return $this->getValueObject('parent'); } - public function setParent(?LinkParent $parent): self + public function setParent(LinkParent|Entity|null $parent): self { - $this->setValueObject('parent', $parent); + if ($parent instanceof LinkParent) { + $this->setValueObject('parent', $parent); + + return $this; + } + + $this->relations->set('parent', $parent); return $this; } diff --git a/application/Espo/Entities/Note.php b/application/Espo/Entities/Note.php index 38d694177b..2827afc6f9 100644 --- a/application/Espo/Entities/Note.php +++ b/application/Espo/Entities/Note.php @@ -224,24 +224,42 @@ class Note extends Entity return $this; } - public function setParent(LinkParent $parent): self + public function setParent(LinkParent|Entity $parent): self { - $this->setValueObject('parent', $parent); + if ($parent instanceof LinkParent) { + $this->setValueObject('parent', $parent); + + return $this; + } + + $this->relations->set('parent', $parent); return $this; } - public function setRelated(LinkParent $related): self + public function setRelated(LinkParent|Entity $related): self { - $this->setValueObject('related', $related); + if ($related instanceof LinkParent) { + $this->setValueObject('related', $related); + + return $this; + } + + $this->relations->set('related', $related); return $this; } - public function setSuperParent(LinkParent $superParent): self + public function setSuperParent(LinkParent|Entity $superParent): self { - $this->set('superParentId', $superParent->getId()); - $this->set('superParentType', $superParent->getEntityType()); + if ($superParent instanceof LinkParent) { + $this->set('superParentId', $superParent->getId()); + $this->set('superParentType', $superParent->getEntityType()); + + return $this; + } + + $this->relations->set('superParent', $superParent); return $this; } diff --git a/tests/integration/Espo/ORM/RelationsTest.php b/tests/integration/Espo/ORM/RelationsTest.php index 6a560e92f8..c5637c1b6c 100644 --- a/tests/integration/Espo/ORM/RelationsTest.php +++ b/tests/integration/Espo/ORM/RelationsTest.php @@ -207,7 +207,7 @@ class RelationsTest extends BaseTestCase $this->assertEquals($account->getId(), $lead2->get('createdAccountId')); $em->refreshEntity($lead1); - + $this->assertEquals(null, $lead1->get('createdAccountId')); $account->setRelatedOriginalLead(null);