[Flow] Re: Relations of created sub-properties
Teo C.
mathaios76 at gmail.com
Mon Sep 23 22:06:49 CEST 2013
Hello,
I tried as suggested to add an hidden field in the fluid template, but still the "one" side (in this case "newConcert"), still comes out empty and the relation is lost in the "many" side ("artists").
Does anybody know what is the recommended way to create sub-properties in the same form of the main property ?
Thanks for any hint !
Teo
Quote: Christian Müller (Ki wrote on Wed, 16 November 2011 12:37
----------------------------------------------------
> Hi Helmut,
>
> seems to be that no one I could ask so far has tried that... Some
> workaround suggestion would be a hidden field:
>
> <f:form.hidden id="artist_concert" property="artists.0.concert"
> value="{newConcert}" />
>
> but that is untested. I hope I can get some more info from the team
> about it to see if I miss something here. But it seems to me that this
> is a use case that could come up all the time...
>
> cheers,
> Christian
>
>
>
> On 16/11/11 09:24, Helmut Hummel wrote:
> <font color="8c8c8c">> Hi Christian,</font>
> <font color="8c8c8c">> </font>
> <font color="8c8c8c">> On 15.11.11 12:11, "Christian Müller (Kitsunet)" wrote:</font>
> <font color="8c8c8c">> </font>
> <font color="9c9c9c">>> Indeed doctrine forces you to set the association on the "One" side of a</font>
> <font color="9c9c9c">>> OneToMany just as you experienced. That is not a bug but a feature;)</font>
> <font color="8c8c8c">> </font>
> <font color="8c8c8c">> Hmm.. but I need to set the relation on the "Many" side. Again my problem:</font>
> <font color="8c8c8c">> </font>
> <font color="8c8c8c">> Concert: one- inversed side</font>
> <font color="8c8c8c">> Artist: many- owning side</font>
> <font color="8c8c8c">> </font>
> <font color="8c8c8c">> </font>
> <font color="8c8c8c">> I want to create a Concert with one Artist, thus creating a form for a</font>
> <font color="8c8c8c">> concert and a field for the artist property:</font>
> <font color="8c8c8c">> </font>
> <font color="8c8c8c">> <f:form.textbox id="artist" property="artists.0.name" /></font>
> <font color="8c8c8c">> </font>
----------------------------------------------------
Quote: Helmut Hummel wrote on Tue, 15 November 2011 01:36
----------------------------------------------------
> Dear FLOW3 experts,
>
> I have a simple many to one relation with two objects, one of them being
> the aggregate root. When I now have a form to create the aggregate root
> object with one association, both objects are created, but the relation
> is lost. In my case the "Artist" is not associated to the concert.
>
>
> Of course I can add
>
> foreach ($newConcert->getArtists() as $artist) {
> $artist->setConcert($newConcert);
> }
>
> to the createAction. But it seems a bit odd to me that this is necessary.
>
> I attached the code I have. What am I missing?
>
>
> Kind regards,
> Helmut
>
> --
> Helmut Hummel
> TYPO3 Security Team Leader, TYPO3 v4 Core Team Member
>
> TYPO3 .... inspiring people to share!
> Get involved: typo3.org
>
> Models:
> ================
>
> class Artist {
>
> /**
> * The name
> * @var string
> */
> protected $name;
>
> /**
> * The concert
> * @var \Helmut\Demo\Domain\Model\Concert
> * @ORM\ManyToOne(inversedBy="artists")
> */
> protected $concert;
> ...
>
> /**
> * A Concert
> *
> * @FLOW3\Scope("prototype")
> * @FLOW3\Entity
> */
> class Concert {
>
> /**
> * The name
> * @var string
> */
> protected $name;
>
> /**
> * The artists
> * @var \Doctrine\Common\Collections\Collection<\Helmut\Demo\Domain\Model\Artist>
> * @ORM\OneToMany(mappedBy="concert")
> */
> protected $artists;
> ...
>
> Concert Controller
> ====================
>
> public function newAction() {
> $newConcert = new \Helmut\Demo\Domain\Model\Concert();
> $this->view->assign('newConcert', $newConcert);
> }
>
> public function initializeCreateAction()
> {
> $this->arguments['newConcert']->getPropertyMappingConfiguration()->allowCreationForSubProperty('artists.0');
> }
>
> /**
> * @param \Helmut\Demo\Domain\Model\Concert $newConcert
> * @return void
> */
> public function createAction(\Helmut\Demo\Domain\Model\Concert $newConcert) {
> $this->concertRepository->add($newConcert);
> $this->redirect('index');
> }
>
>
> FLUID Template
> ====================
>
> <div id="content">
> <f:form controller="Concert" action="create" package="Helmut.Demo" method="post" object="{newConcert}" name="newConcert">
> <label for="name">Concert Name:</label>
> <f:form.textbox id="name" property="name" />
>
>
> <label for="artist">Artist Name:</label>
> <f:form.textbox id="artist" property="artists.0.name" />
>
> <f:form.submit value="Save" />
> </f:form>
> </div>
----------------------------------------------------
More information about the Flow
mailing list