Bug #97472
closed
TYPO3 tries to persist value if model has predefined value even though TCA field type "none"
Added by Alexander Grein about 2 years ago.
Updated almost 2 years ago.
Description
After refactoring a model class and adding a predefined value to a field which TCA type is set to "none", TYPO3 tries to persist this predefined value to a none existing database field, which ends in an exception.
The (simplified) model:
<?php
class Location extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
{
protected float $distance = 0.0;
public function setDistance(float $distance): void
{
$this->distance = $distance;
}
public function getDistance(): float
{
return $this->distance;
}
}
The 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.
Files
- Status changed from New to Needs Feedback
Hi, thanks for creating an issue. To reproduce this properly, could you please share the corresponding exception? I assume the exception occurs in the backend on persisting a record in FormEngine?
The exception will be thrown in the frontend. I will add it later, because I‘m currently not on my computer.
Thanks to Georg for his hint to add this „transidient“ annotation.
Never heared and used it before .
Funny thing, because without adding a predefined value it works as well.
Maybe a more meanfull exception would help to find this „issue“.
I got the issue but in the Backend.
Using TYPO3 v10 though. Not tested on v11 yet.
Pretty sure it worked on older TYPO3 Versions.
Field is of type="none" and has a default value in the TCA.
When i create a database field, it works without error.
gdas_info varchar(255) DEFAULT '' NOT NULL,
So having a database field for these fields is my current workaround.
It is like Georg already wrote:
Extbase does't care about that.
You have to add the annotation "@TYPO3\CMS\Extbase\Annotation\ORM\Transient" to the property definition of your model.
In your case, it should look like this:
/**
* @var string
* @TYPO3\CMS\Extbase\Annotation\ORM\Transient
*/
protected $gdasInfo;
If you have done that and clear all caches, it should work without the extra field to your db.
Alexander Grein wrote in #note-5:
It is like Georg already wrote:
Extbase does't care about that.
You have to add the annotation "@TYPO3\CMS\Extbase\Annotation\ORM\Transient" to the property definition of your model.
In your case, it should look like this:
[...]
If you have done that and clear all caches, it should work without the extra field to your db.
Thanks. i did read that, but i was in the impression that the model class is only parsed for frontend, Backend only uses TCA.
You can also use extbase in the backend. Then it applies there as well.
- Status changed from Needs Feedback to Rejected
I am closing the issue because it was about the frontend and extbase and there is a solution.
if the backend issue is still relevant, please open a new issue and how this can be reproduced
Also available in: Atom
PDF