[Flow] Re: How to update aggregates with a single form

Sil via silvia.conti at bluewin.ch
Fri Sep 20 15:34:21 CEST 2013


Hi,
I had exactly your problem and I didn't find any solution but using repositories for each class. Does someone know how to manage editing of aggregates properly? Are there examples?
Do I have maybe to delete the entire collection and re-create it again?

Thanks
Sil via

Quote: Ivan Ruiz Gallego wrote on Wed, 28 September 2011 16:12
----------------------------------------------------
> 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 
> />
> 	<f:for each="{foo.bars}" as="bar" iteration="i">
> 		Bar's name: <f:form.textbox property="bars.{i.index}.name" 
> value="{bar.name}" />
> 	</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 Flow mailing list