register('broker_rut', (new Common\Implement\Repository\Mapper()) ->setProperty('broker') ->setFunction(function($data) { return $this->brokerRepository->fetchById($data['broker_rut']); })) ->register('representative_rut', (new Common\Implement\Repository\Mapper()) ->setProperty('representative') ->setDefault(null) ->setFunction(function($data) { try { return $this->personaRepository->fetchById($data['representative_rut']); } catch (Common\Implement\Exception\EmptyResult) { return null; } })) ->register('legalName', (new Common\Implement\Repository\Mapper()) ->setDefault(null)); return $this->parseData(new Model\Proyecto\Broker\Data(), $data, $map); } public function save(Common\Define\Model $model): Model\Proyecto\Broker\Data { $model->id = $this->saveNew( ['broker_rut', 'representative_rut', 'legal_name'], [$model->broker->rut, $model->representative?->rut, $model->legalName]); return $model; } public function edit(Common\Define\Model $model, array $new_data): Model\Proyecto\Broker\Data { return $this->update($model, ['broker_rut', 'representative_rut', 'legal_name'], $new_data); } public function fetchByBroker(int $brokerRut): Model\Proyecto\Broker\Data { $query = $this->connection->getQueryBuilder() ->select() ->from($this->getTable()) ->where('broker_rut = :broker_rut'); return $this->fetchOne($query, ['broker_rut' => $brokerRut]); } }