Project

General

Profile

Actions

Bug #32549

closed

DataMapper returns empty array for MM relations on opposite field side because relation field is empty

Added by Klaus Bitto almost 13 years ago. Updated over 9 years ago.

Status:
Closed
Priority:
Could have
Assignee:
-
Category:
-
Target version:
-
Start date:
2011-12-14
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
6.2
PHP Version:
Tags:
Complexity:
Is Regression:
No
Sprint Focus:

Description

Given you have two models:

Apple

Banana

The two models are related with an MM table. Apple is local (with relation field Apple::$bananas),
Banana is foreign, using MM_opposite_field on Banana::$apples.

1) Add a Banana to an apple ( $someApple->addBanana($somebanana); )

2) In the database, Apple.bananas will now be 1. Banana.apples should be 1 but it will be '' (empty).

3) If you open your banana (=opposite/foreign side) in the BE list view, you will see the apple in the select field defined in the TCA, as MM_opposite_field is defined as Apple.bananas. This means that Core does NOT care about whether or not Banana.apples is empty or not.

4) If on the other hand you use extbase, and request $somebanana->getApples(), you will get an empty object storage. Why?

    protected function fetchRelatedEager(Tx_Extbase_DomainObject_DomainObjectInterface $parentObject, $propertyName, $fieldValue = '') {
        if ($fieldValue === '') return array();
        [...]
    }

This is broken.

a) Either, when updating an MM relation, the opposite field needs to be updated with the corresponding count as well (neither core nor extbase are doing that)
b) or when resolving the relation from the opposite field side (or possibly any side), there CANNOT be a check for if the field value is empty. (core can deal with that, extbase cannot)

When you want to check this bug, make sure that when you open your banana in the back end, not to save it. Core will update Banana.apples (=opposite field) if saved directly. It will merely NOT update Banana.apples if you save an apple. I hope I could make clear what I mean.

PS: Probably this guy's problem is related: http://lists.typo3.org/pipermail/typo3-dev/2010-February/038917.html although it only touches Core, not extbase (which are two different problems).

Actions

Also available in: Atom PDF