[Flow] How to build One-To-Many Forms

Axel Wüstemann awu at qbus.de
Sun Nov 3 20:02:06 CET 2013


Hi there,

as in other posts I mentioned, my application is on fishery inspection. 
Some kinds of inspections have one to many relations.

The "One" is the inspection itself. An example is, what I tried to 
translate as "deposit inspection" (Anlandekontrolle). It has the 
inspection, with properties as "date", "inspectionOfficer", the 
"harbour" where the catch was broad to the land etc. The "manys" are the 
catches ("deposits" in my translation) - the kind of fishes and its amount.

So I have a form with fields of the "depositInspection" followed by a 
table, with each row representing a "deposit", consisting of a selectbox 
for looking up the kind of fish and an input field for the related amount.

I built my domain models accordingly - a "depositInspection" model which 
contains a "deposits" property of the type 
\Doctrine\Common\Collections\Collection.:
/**
  * Anlandungen
  *
  * @var 
\Doctrine\Common\Collections\Collection<\XXX\Intranet\FisheryInspection\Domain\Model\Deposit>
  * @ORM\OneToMany(mappedBy="depositInspection")
  */
protected $deposits;

In the deposit model:
	
/**
  * zugehörige Anlandekontrolle
  *
  * @var XXX\Intranet\FisheryInspection\Domain\Model\DepositInspection
  * @ORM\ManyToOne(inversedBy="deposits")
  * @ORM\JoinColumn(name="ANLANDEKTR_ID", referencedColumnName="ID")
  */
protected $depositInspection;

The forms for new and edit I built according to that:
http://lists.typo3.org/pipermail/flow/2013-June/003909.html

Initialy for a new depositInspection I have 5 rows of deposits, but I 
need to have a field and action button to get more (or less) deposit 
rows - in the new as well as in the edit form.

In order to biuld the new form, in the constructor of the 
depositInspection I create an empty deposit and call five times 
$this->addDeposit($emptyDeposit);

Question 1:
==============
Is that a good idea? How to add more rows? This should be some kind of 
Ajax action. Should I do simply the same as in the constructor -  add 
some more empty deposits to te deposits collection?

This works for the first step, so the rows apear in the new form and in 
the edit form the deposit rows of a certain depositInspection are 
correctly populated.

<f:for each="{newDepositInspection.deposits}" as="deposit" iteration="i">
<div class="form-group">
  <div class="..">Nr. {i.index}</div>
  <div class=".."><f:form.select property="deposit.{i.index}.deposit" 
options="{deposits}" ../></div>
  <div class=".."><f:form.textfield property="deposit.{i.index}.amount" 
.. /></div>
</div>
</f:for>

In the edit form I have additionally
<f:form.hidden name="deposit.{i.index}.__identifier" value="{deposit.id}" />

When I submit the form I get

  Property "deposit" was not found in target object of type 
"XXX\Intranet\FisheryInspection\Domain\Model\DepositInspection"

The related property in DepositInspectionis called "deposits" not 
"deposit" -  but it is a collection of "deposit"

Question 2:
===========
What goes wrong here? How to name the "toMany" properties in the form 
correctly?

Thank you for your advise.

Axel






More information about the Flow mailing list