From 75497db1a7b152f23cf0b5bd7c7b093a59625dc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Sat, 16 Mar 2024 19:16:26 +0100 Subject: [PATCH] Remove no longer needed explicit field type in HasOne relations (#2184) --- demos/form-control/lookup.php | 4 ++-- demos/form/form2.php | 4 ++-- demos/init-db.php | 13 ------------- 3 files changed, 4 insertions(+), 17 deletions(-) diff --git a/demos/form-control/lookup.php b/demos/form-control/lookup.php index ba5c837970..a2fa4cbc9e 100644 --- a/demos/form-control/lookup.php +++ b/demos/form-control/lookup.php @@ -31,10 +31,10 @@ $model = new Model($app->db, ['table' => 'test']); // lookup without plus button -$model->hasOne('country1', ['model' => [Country::class], 'type' => WrappedIdType::NAME]); +$model->hasOne('country1', ['model' => [Country::class]]); // lookup with plus button -$model->hasOne('country2', ['model' => [Country::class], 'type' => WrappedIdType::NAME, 'ui' => ['form' => ['plus' => true]]]); +$model->hasOne('country2', ['model' => [Country::class], 'ui' => ['form' => ['plus' => true]]]); $form->setModel($model->createEntity()); diff --git a/demos/form/form2.php b/demos/form/form2.php index 5aef3baf70..fec816cea7 100644 --- a/demos/form/form2.php +++ b/demos/form/form2.php @@ -96,8 +96,8 @@ protected function init(): void $this->addField('name', ['required' => true]); $this->addField('surname', ['ui' => ['placeholder' => 'e.g. Smith']]); $this->addField('gender', ['enum' => ['M', 'F']]); - $this->hasOne('country_lookup_id', ['model' => [Country::class], 'type' => WrappedIdType::NAME]); // this works fast - $this->hasOne('country_dropdown_id', ['model' => [Country::class], 'type' => WrappedIdType::NAME, 'ui' => ['form' => new Form\Control\Dropdown()]]); // this works slow + $this->hasOne('country_lookup_id', ['model' => [Country::class]]); // this works fast + $this->hasOne('country_dropdown_id', ['model' => [Country::class], 'ui' => ['form' => new Form\Control\Dropdown()]]); // this works slow } #[\Override] diff --git a/demos/init-db.php b/demos/init-db.php index 0fa1acaf83..06a3dd2076 100644 --- a/demos/init-db.php +++ b/demos/init-db.php @@ -7,7 +7,6 @@ use Atk4\Core\Factory; use Atk4\Data\Field; use Atk4\Data\Model; -use Atk4\Data\Reference; use Atk4\Ui\Exception; use Atk4\Ui\Form; use Atk4\Ui\Table; @@ -299,17 +298,6 @@ public function addField(string $name, $seed = []): Field return parent::addField($name, $seed); } - #[\Override] - public function hasOne(string $link, array $defaults): Reference - { - // TODO remove once HasOne reference can infer type from their model - if (!isset($defaults['type'])) { - $defaults['type'] = WrappedIdType::NAME; - } - - return parent::hasOne($link, $defaults); - } - #[\Override] public function getId(): ?WrappedId { @@ -437,7 +425,6 @@ protected function init(): void $this->hasOne($this->fieldName()->client_country_iso, [ 'model' => [Country::class], 'theirField' => Country::hinting()->fieldName()->iso, - 'type' => 'string', 'ui' => [ 'form' => [Form\Control\Line::class], 'table' => [Table\Column\CountryFlag::class],