Skip to content

Commit

Permalink
convert all demo IDs from integer to WrappedId
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Feb 13, 2024
1 parent 17dcf89 commit 3323ba2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 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]]);
$model->hasOne('country1', ['model' => [Country::class], 'type' => WrappedIdType::NAME]);

// lookup with plus button
$model->hasOne('country2', ['model' => [Country::class], 'ui' => ['form' => ['plus' => true]]]);
$model->hasOne('country2', ['model' => [Country::class], 'type' => WrappedIdType::NAME, '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]]); // this works fast
$this->hasOne('country_dropdown_id', ['model' => [Country::class], 'ui' => ['form' => new Form\Control\Dropdown()]]); // this works slow
$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
}

#[\Override]
Expand Down
13 changes: 13 additions & 0 deletions demos/init-db.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ protected function init(): void

parent::init();

$this->getField($this->idField)->type = WrappedIdType::NAME;

$this->initPreventModification();

if ($this->getPersistence()->getDatabasePlatform() instanceof PostgreSQLPlatform || class_exists(CodeCoverage::class, false)) {
Expand All @@ -296,6 +298,17 @@ public function addField(string $name, $seed = []): Field
return parent::addField($name, $seed);
}

#[\Override]
public function hasOne(string $link, array $defaults = [])
{
// 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

0 comments on commit 3323ba2

Please sign in to comment.