Skip to content

Commit

Permalink
Remove no longer needed explicit field type in HasOne relations (#2184)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek authored Mar 16, 2024
1 parent b51f5df commit 75497db
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 17 deletions.
4 changes: 2 additions & 2 deletions demos/form-control/lookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
4 changes: 2 additions & 2 deletions demos/form/form2.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
13 changes: 0 additions & 13 deletions demos/init-db.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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],
Expand Down

0 comments on commit 75497db

Please sign in to comment.