Bug #98224
openPredefined extbase model property value cause exception of not existing database field
0%
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;
}
Updated by Alexander Grein about 2 years ago
Additional to removing the default value from the property, I also have to remove the php >=7.4 property type.
Not working:
/**
* @var float
* @Transient
*/
protected float $distance = 0.0;
working:
/**
* @var float
* @Transient
*/
protected $distance;
Updated by Alexander Grein about 2 years ago
- PHP Version changed from 8.2 to 8.1
Updated by Alexander Grein about 2 years ago
Am I the only one with this problem?
To make it more clear, this example code of the official documentation is not working!:
https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ExtensionArchitecture/Extbase/Reference/Annotations.html#transient