[TYPO3-mvc] Removing a 1:1 relation in Fluid

Steffen Müller typo3 at t3node.com
Thu May 12 13:58:25 CEST 2011


Hi.

I have problems removing a 1:1 relation between two model objects with 
extbase/fluid. I can add a new relation but not remove an existing one.

This is my Domain (used inside a BE module):

I have a "Template" (entity + root aggregate) with a 1:1 relation to 
"Skin" (entity). A Template can have 0 or 1 skin related.
To select the skin, I have edit and update action in the Template 
controller:

/**
  * @return void
  */
public function editAction() {
   $template = $this->templateRepository->findNextInRootline();
   $this->view->assign('template', $template);
   $this->view->assign('skins', $this->skinRepository->findAll());
}

/**
  * @param Tx_T3temple_Domain_Model_Template $template Template
  * @return
*/
public function updateAction(Tx_Ext_Domain_Model_Template $template) {
   $this->templateRepository->update($template);
}

In the view, users can select or unselect a Skin for the Template. I 
create a list of all available Skins with Fluid. Each Skin in this list 
has a button, either to add the skin relation to the Template, or to 
remove it, if a relation already exists.

This is how the fluid template looks like. I use a hidden input field 
for the Skin argument, because goal is to have only one button for each 
Skin.

<f:for each="{skins}" as="skin">
  <f:form method="post" controller="Template" action="update" 
name="template" object="{template}">
  <f:if condition="{skin} == {template.skin}" >
  <f:then>

    <f:form.hidden property="skin" value="0" />

    <f:form.submit class="button" value="unselect">
      <input class="button" type="submit" name="" value="Unselect" />
   </f:form.submit>
  </f:then>
  <f:else>

    <f:form.hidden property="skin" value="{skin}" />

    <f:form.submit class="button" value="select">
      <input class="button" type="submit" name="" value="Select" />
    </f:form.submit>
  </f:else>
  </f:if>
</f:form>
</f:for>

So far, selecting a Skin works. But unselecting does not.

Although I set skin property to "0" in the hidden form field, the 
Template model object in updateAction still has the old skin related. 
(so it is not marked as dirty and stays unchanged)

<f:form.hidden property="skin" value="{skin}" />
... is parsed to:
<input type="hidden" name="tx_ext_web_mymod[template][skin][__identity]" 
value="4" />

<f:form.hidden property="skin" value="0" />
... is parsed to:
<input type="hidden" name="tx_ext_web_mymod[template][skin]" value="0" />

Changing the hidden field to:
<f:form.hidden name="template[skin][__identity]" value="0" />
does not help.

Do you have an idea how to unset a 1:1 relation in fluid forms?



-- 
cheers,
Steffen

TYPO3 Blog: http://www.t3node.com/
Twitter: http://twitter.com/t3node


More information about the TYPO3-project-typo3v4mvc mailing list