Hi Devs,
I have a one to one relationship set up between a device and its internal camera. The camera is a selectable field on the device. The camera select modal has a primary filter on it created using the selectDefs/primary filter method described here. It filters out cameras which are already attached to another device eg
But now I have a requirement to match the type of the device (macro/micro) to the type of the camera (macro/micro). To do that I need access to the type of the device (data on the current record)... The id or the type itself would work but I can't figure out how to get access to that info. Can anyone please help?
Cheers,
Clare
I have a one to one relationship set up between a device and its internal camera. The camera is a selectable field on the device. The camera select modal has a primary filter on it created using the selectDefs/primary filter method described here. It filters out cameras which are already attached to another device eg
PHP Code:
<?php
namespace Espo\Custom\Select\Camera;
use Espo\Core\Select\Primary\Filter;
use Espo\ORM\Query\SelectBuilder;
use Espo\ORM\Query\Part\Condition as Cond;
use Espo\ORM\Query\SelectBuilder as QueryBuilder;
use Espo\Core\Select\Text\Filter\Data;
class NotAttachedToDevice implements Filter
{
// https://forum.espocrm.com/forum/developer-help/75890-how-to-own-primary-filter-espocrm-7-0-x
// public function apply(QueryBuilder $queryBuilder, Data $data): void
public function apply(SelectBuilder $queryBuilder): void
{
$subQuery = QueryBuilder::create()
->select('id')
->from('Device','device')
->where([
// if the camera is currently attached (deviceCurrCameraId is set OR production camera is set but not current - that is, it hasn't been replaced) then it can't be used
'OR' => [
[
'device.deviceCurrCameraId:' => 'Camera.id',
],
[
'device.deviceProdCameraId:' => 'Camera.id',
'device.deviceCurrCameraId' => null,
]
]
])
->build();
$queryBuilder->where( Cond::not(Cond::exists($subQuery)));
}
}
Cheers,
Clare
Comment