[FLOW3-general] How to update aggregates with a single form

Ivan Ruiz Gallego ivan at loglan.net
Wed Sep 28 16:12:41 CEST 2011


Hi,

I have a model Foo, which has a OneToMany association to a model Bar 
(both are entities, Foo and Bar build an aggregate, Foo is the aggregate 
root). Both Foo and Bar have a property $name. I create an instance of 
Foo, which is related to a given number of instances of Bar. This works 
fine, so far. My problem relates to the update of such an association.

I have an update form, which looks like:

<f:form action="update" object="{foo}" name="foo">
	Foo's name: <f:form.textbox property="name" value="{foo.name}" /><br 
/><br />
	<f:for each="{foo.bars}" as="bar" iteration="i">
		Bar's name: <f:form.textbox property="bars.{i.index}.name" 
value="{bar.name}" /><br /><br />
	</f:for>
	<f:form.submit value="submit" />
</f:form>

The controller action update looks like as simple as this:

/**
   * Update a foo
   *
   * @param \Acme\MyPackage\Domain\Model\Foo $foo Foo to update
   * @return void
   */
public function updateAction(\Acme\MyPackage\Domain\Model\Foo $foo) {
	$this->fooRepository->update($foo);
	$this->flashMessageContainer->add('foo updated');
	$this->redirect('index');
}

When I submit the form, FLOW3 doesn't update the bars which were already 
associated with the foo, but it create new ones. So if initially foo had 
3 bars, after updating it has 6. I've taken a look to the HTML code 
generated by Fluid and I can see that the identity of the Foo instance 
is there, but I see nothing related to the identity of the Bar instances.

What am I missing? Maybe is something wrong in the Fluid template?

Thanks,
Ivan.


More information about the FLOW3-general mailing list