Mateng
Mateng

Reputation: 3734

TYPO3 Fluid: Map m:n values from multiple select form to model

I have a m:n relation in my domain model:

In the inquiry model this is defined:

/**
 * @var Tx_Extbase_Persistence_ObjectStorage<Tx_MyExt_Domain_Model_Investigator>
 */
protected $investigator;

The investigator domain model is mapped to the fe_user table of TYPO3, which is noted properly in the configuration (ext_typoscript_setup.txt):

config.tx_extbase{
    persistence{
        classes{
            Tx_MyExt_Domain_Model_Investigator {
                mapping {
                    recordType = Tx_Extbase_Domain_Model_FrontendUser
                    tableName = fe_users
                }
            }
        }

This works fine, I can display and edit inquiry records in the backend and frontend. However, when I want to change the investigators assigned to one inquiry (from edit action), I get an exception after submitting my form:

#1297759968: Exception while property mapping at property path "investigator":
No converter found which can be used to convert from "array" to
"Tx_Extbase_Persistence_ObjectStorage"

The multiselect-box that I use for this is created like that:

<f:form.select multiple="true" size="10" property="investigator" 
value="{inquiry.investigator}" options="{allInvestigators}" 
optionLabelField="name" />

Which is rendered like this:

<select name="tx_myext_inquiry[inquiry][investigator][]" size="10" multiple="true">
    <option value="362">John Doe</option>
    <option value="590">Jane Doe</option>
    <option selected="selected" value="361">Steve Miller</option>
    <option value="720">James Brown</option>
    <option value="726">Janis Joplin</option>
</select>

{allInvestigators} is an array with all users from the group "investigators". The values already stored are marked with "selected", which proves that some of my code is correct ;).

I tried fiddling around with the type converter (Tx_Extbase_Property_TypeConverter_PersistentObjectConverter Dok) in the InquiryController to cast my array to an object, but it to no avail. The field investigator is passed as an array to the update action, which triggers the exception.

I spend five hours on this now, need to move on.

(Any questions for more details will be answered ASAP)


Edit:
Environment: TYPO3 version 6.1.1, Fluid 6.1.0, Extbase 6.1.0

Upvotes: 0

Views: 3739

Answers (3)

minifranske
minifranske

Reputation: 1315

This is currently a known problem in the 6.* branches of TYPO3.

See http://forge.typo3.org/issues/54289 there is currently a patch pending to get this fixed.

Upvotes: 1

Mateng
Mateng

Reputation: 3734

I found the culprit in the model definition in Classes/Domain/Model/Inquiry.php

/**
 * @var Tx_Extbase_Persistence_ObjectStorage<Tx_MyExt_Domain_Model_Investigator>
 */
protected $investigator;

I changed (part of) the @var annotation to name space style:

/**
 * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<Tx_MyExt_Domain_Model_Investigator>
 */
protected $investigator;

Now the update process works. I guess in our project we need to standardize the model to name spaces. If this is a bug, I will file it at forge.typo3.org.

Upvotes: 2

froemken
froemken

Reputation: 420

I have tested it with TYPO3 6.1 and TYPO3 6.2-dev from GIT and can't reproduce this problem. So it would be nice if you can give up some environment informations. Please start with your current TYPO3-Version.

Upvotes: 0

Related Questions