Project

General

Profile

Actions

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.

Status:
Rejected
Priority:
Should have
Assignee:
-
Category:
-
Target version:
-
Start date:
2022-04-25
Due date:
% Done:

0%

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

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

Screenshot_20220531_152802.png (12.7 KB) Screenshot_20220531_152802.png Sascha Löffler, 2022-05-31 13:32
Actions #1

Updated by Oliver Bartsch about 2 years ago

  • 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?

Actions #3

Updated by Alexander Grein about 2 years ago

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“.

Actions #4

Updated by Sascha Löffler almost 2 years ago

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.

Actions #5

Updated by Alexander Grein almost 2 years ago

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.

Actions #6

Updated by Sascha Löffler almost 2 years ago

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.

Actions #7

Updated by Alexander Grein almost 2 years ago

You can also use extbase in the backend. Then it applies there as well.

Actions #8

Updated by Georg Ringer almost 2 years ago

  • 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

Actions

Also available in: Atom PDF