Commit 0e37d598 authored by Morton Jonuschat's avatar Morton Jonuschat Committed by Anja Leichsenring
Browse files

[FOLLOWUP][BUGFIX] Extbase: Use fully populated records in insertObject()

As it is common practice to define object properties in Extbase models
without default values (resulting in a NULL value) while defining the
database columns as `DEFAULT '' NOT NULL` these columns need to be
skipped when preparing a new record for insertion into the database.
This allows the database to use the configured defaults for columns
not included in the insert statement.

To properly support strict databases in an Extbase extension/model it is
required to configure identical/compatible default values in the
database schema and the model. This problem cannot be solved completely
programmatically.

Resolves: #69247
Related: #69084
Releases: master
Change-Id: I9de6a68a9eac25e171e3bfde6314366dad1ae346
Reviewed-on: http://review.typo3.org/42821

Reviewed-by: Markus Klein's avatarMarkus Klein <markus.klein@typo3.org>
Reviewed-by: Wouter Wolters's avatarWouter Wolters <typo3@wouterwolters.nl>
Tested-by: Markus Klein's avatarMarkus Klein <markus.klein@typo3.org>
Reviewed-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
parent 86ebff47
============================================================================
Important: #69084 - Adding Extbase Objects with NOT NULL columns has changed
============================================================================
Description
===========
To better support databases that don't silently convert NULL values to
an empty default value for database column defined as NOT NULL the
`ìnsertObject()`` method tries to determine the appropriate value for
a column.
Extbase object properties that have a value of NULL will be skipped when
preparing the record to enable the DBMS default value to be used. This
behavior has not changed compared to TYPO3 CMS 7.4 but allows proper
support for DBMS that are strict about NOT NULL columns by defining
appropriate default values for properties in the models.
Example database schema:
.. code-block:: sql
CREATE TABLE tx_blogexample_domain_model_blog (
title varchar(255) DEFAULT '' NOT NULL
);
Example model definition:
.. code-block:: php
class Blog extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
/**
* The blog's title.
*
* @var string
*/
protected $title = '';
}
......@@ -657,11 +657,8 @@ class Backend implements \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface
// MM type relation
$row[$columnMap->getColumnName()] = 0;
}
} else {
// Check explicitly for NULL, as getPlainValue would convert this to 'NULL'
$row[$columnMap->getColumnName()] = $propertyValue !== NULL
? $this->dataMapper->getPlainValue($propertyValue)
: NULL;
} elseif ($propertyValue !== NULL) {
$row[$columnMap->getColumnName()] = $this->dataMapper->getPlainValue($propertyValue);
}
}
$this->addCommonFieldsToRow($object, $row);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment