formula record relate support mass relate
This commit is contained in:
@@ -61,9 +61,19 @@ class RelateType extends \Espo\Core\Formula\Functions\Base
|
||||
$entity = $em->getEntity($entityType, $id);
|
||||
if (!$entity) return null;
|
||||
|
||||
if ($em->getRepository($entityType)->isRelated($entity, $link, $foreignId))
|
||||
if (is_array($foreignId)) {
|
||||
foreach ($foreignId as $itemId) {
|
||||
$em->getRepository($entityType)->relate($entity, $link, $itemId);
|
||||
}
|
||||
return true;
|
||||
|
||||
return $em->getRepository($entityType)->relate($entity, $link, $foreignId);
|
||||
} else if (is_string($foreignId)) {
|
||||
if ($em->getRepository($entityType)->isRelated($entity, $link, $foreignId)) {
|
||||
return true;
|
||||
}
|
||||
return $em->getRepository($entityType)->relate($entity, $link, $foreignId);
|
||||
} else {
|
||||
throw new Error("Formula record\\relate: foreignId type is wrong.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -421,6 +421,25 @@ class FormulaTest extends \tests\integration\Core\BaseTestCase
|
||||
$this->assertTrue($em->getRepository('Account')->isRelated($a, 'opportunities', $o));
|
||||
}
|
||||
|
||||
public function testRecordRelate1()
|
||||
{
|
||||
$fm = $this->getContainer()->get('formulaManager');
|
||||
$em = $this->getContainer()->get('entityManager');
|
||||
|
||||
$a = $em->createEntity('Account', [
|
||||
'name' => '1',
|
||||
]);
|
||||
$o = $em->createEntity('Opportunity', [
|
||||
'name' => '1',
|
||||
]);
|
||||
|
||||
$script = "record\\relate('Account', '".$a->id."', 'opportunities', list('".$o->id."'))";
|
||||
$result = $fm->run($script, $contact);
|
||||
|
||||
$this->assertTrue($result);
|
||||
$this->assertTrue($em->getRepository('Account')->isRelated($a, 'opportunities', $o));
|
||||
}
|
||||
|
||||
public function testRecordUnrelate()
|
||||
{
|
||||
$fm = $this->getContainer()->get('formulaManager');
|
||||
|
||||
Reference in New Issue
Block a user