Project

General

Profile

Actions

Bug #98224

open

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

Added by Alexander Grein almost 2 years ago. Updated over 1 year 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 #1

Updated by Alexander Grein almost 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;

Actions #2

Updated by Alexander Grein almost 2 years ago

  • PHP Version changed from 8.2 to 8.1
Actions #3

Updated by Alexander Grein over 1 year 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

Actions

Also available in: Atom PDF