Project

General

Profile

Actions

Bug #98224

open

Predefined extbase model property value cause exception of not existing database field

Added by Alexander Grein about 2 years ago. Updated about 2 years ago.

Status:
New
Priority:
Should have
Assignee:
-
Category:
Extbase
Target version:
-
Start date:
2022-08-29
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
11
PHP Version:
8.1
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

After adding a predefined value to a field which TCA type is set to "none" and the property annotation is @Transient, TYPO3 tries to persist this predefined value to a none existing database field, which ends in an exception.

The (simplified) model:

<?php
namespace Vendor\Extension\Domain\Model;
use TYPO3\CMS\Extbase\Annotation\ORM\Transient;
class Location extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
{
  /**
   * @var float
   * @Transient
   */
  protected float $distance = 0.0;

  public function setDistance(float $distance): void
  {
    $this->distance = $distance;
  }
  public function getDistance(): float
  {
    return $this->distance;
  }
}

The relevant TCA field config:

'columns' => [
  'distance' => [
    'config' => [
      'type' => 'none',
    ],
  ],
]

I use this field to add a calculated distance to a location depending of the users location.

Then only way to get rid of this problem is to remove the predefinition value "0.0" from the property and change the getter this way:

public function getDistance(): float
{
  return $this->distance ?? 0.0;
}

Actions

Also available in: Atom PDF