insertOnDuplicateUpdate is very useful when integrating with external services.
External entities have their own Id's and in the espo we have
It would be nice if insertOnDuplicateUpdate have full entity support:
1. Default ID (this code without setting ID don't work, cause PDOException SQLSTATE[HY000]: General error: 1364 Field 'id' doesn't have a default value in /application/Espo/ORM/SqlExecutor.php:72)
2. Support all field types, included jsonType. jsonType fullinfo is null after insertOnDuplicateUpdate($e ...
3. Support fetched id if duplicate founded.
Now $e->id is preliminarily generated value, not actual.
4. Support additional link fields. This code cause exception. But in saveEntity all ok.
External entities have their own Id's and in the espo we have
Code:
{ "fields": { "externalId": { "type": "int" } }, "indexes": { "externalIdUnique": { "type": "unique", "columns": [ "externalId", "deleted" ] } }
1. Default ID (this code without setting ID don't work, cause PDOException SQLSTATE[HY000]: General error: 1364 Field 'id' doesn't have a default value in /application/Espo/ORM/SqlExecutor.php:72)
PHP Code:
$em = $this->getEntityManager();
$e = $em->getEntity('Host');
$id = \Espo\Core\Utils\Util::generateId();
$e->set([
// 'id' => $id,
'externalId'=> '999',
'name' => 'Модифицированный'
]);
$s = $em->getMapper('RDB')->insertOnDuplicateUpdate($e, [
'name'
]);
PHP Code:
$e->set([
'fullInfo' => '{"a":"b"}'
]);
Now $e->id is preliminarily generated value, not actual.
4. Support additional link fields. This code cause exception. But in saveEntity all ok.
PHP Code:
set([
'HostUsersIds' => $hI,
'HostUsersNames' => $hN,
'HostUsersColumns' => $hC
]);
Comment