[TYPO3-mvc] RFC #8973: DataMapper mapps FALSE into empty related property
Felix Oertel
mehl at foertel.com
Wed Jul 21 11:26:19 CEST 2010
This is an SVN patch request.
Type: Bugfix
Bugtracker references:
http://forge.typo3.org/issues/8973
Branches:
trunk, 1.2.0
Problem:
When you've got a model with a property holding an related object,
extbase tries to find the corresponding row in the database (via
DataMapper::fetchRelatedEager() and the query-object). If there is no
such row (because it either does not exist or it is flagged hidden or
deleted), the query-object will return an empty array.
The DataMapper will then give this empty array to
DataMapper::mapResultToPropertyValue(). In line 451 current() is called
on this empty array and the result is assigned as propertyValue.
Unfortunately current() returns FALSE on an empty array. You end up with
the property's value set to FALSE if the related object was not found.
Solution:
I would suggest to map NULL here, because it's an empty property
(without the corresponding object).
Notes:
Mapping FALSE will get you in trouble when you try to give this property
to another function using a typeHint. NULL will pass fine but FALSE will
throw an exception like "PHP Catchable Fatal Error: Argument 1 passed to
Tx_MyExt_Controller_BaseController::getSomeFancyStuff() must be an
instance of Tx_MyExt_Domain_Model_RelatedObject, boolean given".
No core class depends on returning FALSE here.
regards, foertel
More information about the TYPO3-project-typo3v4mvc
mailing list