Code:
DEBUG: API (21000) SQLSTATE[21000]: Cardinality violation: 1242 Subquery returns more than 1 row; GET /Contact; Route pattern: /{controller}; Route params: Array ( [controller] => Contact [action] => index )
use Espo\Entities\ArrayValue;
use Espo\ORM\Query\SelectBuilder;
$subQuery = SelectBuilder::create()
->select('entityId')
->from(ArrayValue::ENTITY_TYPE)
->where([
'entityType' => 'Contact',
'attribute' => 'cmmTypes',
'value' => ['1', '6'],
])->build();
$queryBuilder->where(['id' => $subQuery]);
DEBUG: API (21000) SQLSTATE[21000]: Cardinality violation: 1242 Subquery returns more than 1 row; GET /Contact; Route pattern: /{controller}; Route params: Array ( [controller] => Contact [action] => index )
<?php namespace Espo\Custom\Classes\Select\CaseObj\PrimaryFilters; use Espo\Core\Select\Primary\Filter; use Espo\ORM\Query\SelectBuilder; class DocumentID implements Filter { public function apply(SelectBuilder $queryBuilder): void { $queryBuilder->where([ 'type=' => ['ID'] ]); } }
class DocumentID implements Filter { public function apply(SelectBuilder $queryBuilder): void { $queryBuilder->where([ 'type=' => ['ID'] ]); } } class DocumentInvoice implements Filter ... 'type=' => ['Invoice'] class DocumentAgreement implements Filter ... 'type=' => ['Agreement']
<?php
namespace Espo\Custom\Classes\Select\Epidemio\PrimaryFilters;
use Espo\Core\Select\Primary\Filter;
use Espo\ORM\Query\SelectBuilder;
use Espo\Entities\ArrayValue;
use Espo\ORM\Query\Part\Condition as Cond;
use Espo\Core\Select\Where\ConverterFactory;
use Espo\Entities\User;
use Espo\Core\Select\Where\ItemBuilder;
class Adult implements Filter
{
private $converterFactory;
private $user;
public function __construct(ConverterFactory $converterFactory, User $user){
$this->converterFactory = $converterFactory;
$this->user = $user;
}
public function apply(SelectBuilder $queryBuilder): void
{
$converter = $this->converterFactory->create('Epidemio', $this->user);
$whereClause = $converter->convert(
$queryBuilder,
(new \Espo\Core\Select\Where\ItemBuilder)
->setAttribute('target')
->setType('arrayAllOf')
->setValue(['Adult'])
->build()
);
$queryBuilder->where($whereClause);
}
}
{
"primaryFilterClassNameMap": {
"adult": "Espo\\Custom\\Classes\\Select\\Epidemio\\PrimaryFilters\\Adult"
},
"boolFilterClassNameMap": {
"active": "Espo\\Custom\\Classes\\Select\\Epidemio\\BoolFilters\\Active"
}
}
use Espo\Entities\ArrayValue;
use Espo\ORM\Query\SelectBuilder;
$subQuery = SelectBuilder::create()
->select('entityId')
->from(ArrayValue::ENTITY_TYPE)
->where([
'entityType' => 'YourEntityType',
'attribute' => 'yourField',
'value' => $valueList,
])
->build();
$queryBuilder->where(['id' => $subQuery]);
<?php
namespace Espo\Custom\Classes\Select\Epidemio\PrimaryFilters;
use Espo\Core\Select\Primary\Filter;
use Espo\ORM\Query\SelectBuilder;
use Espo\ORM\Query\Part\Condition as Cond;
class MultiEnumField implements Filter
{
public function __construct()
{
}
public function apply(SelectBuilder $queryBuilder): void
{
$queryBuilder->where([
'MultiEnumField' => ['value1', 'value2'],
]);
}
}
Leave a comment: