[FLOW3-general] Question about associations and JsonView
Davide CD
dmichelangeli at hotmail.com
Tue Apr 24 11:27:55 CEST 2012
Sorry if I bother you again, but I really can't get this to work...
class Hotel{/*** Users is an array collection of User objects* @var \Doctrine\Common\Collections\Collection<\DKM\Services\Domain\Model\User>* @ORM\ManyToMany(inversedBy="hotels" , cascade={"persist"})* @ORM\JoinTable(name="dkm_services_domain_model_hotel_user_join") */ protected $users;
/*** Get the Hotel's users** @return \Doctrine\Common\Collections\Collection The Hotel's users*/public function getUsers() { return $this->users;}/** * Sets this Hotel's users * * @param \Doctrine\Common\Collections\Collection $users The Hotel's users * @return void */public function setUsers(\Doctrine\Common\Collections\Collection $users) { $this->users = $users;}
}
class User{
/** * @var \Doctrine\Common\Collections\Collection<\DKM\Services\Domain\Model\Hotel> * @ORM\ManyToMany(mappedBy="users" , cascade={"persist"}) */ protected $hotels; /** * Get the Users's hotels * * @return \Doctrine\Common\Collections\Collection The Users's hotels */ public function getHotels() { return $this->hotels; }
/** * Sets this User's hotel * * @param \Doctrine\Common\Collections\Collection $users The User's hotels * @return void */ public function setHotels(\Doctrine\Common\Collections\Collection $hotels) { $this->hotels = $hotels; }
}
I have an association table (jointable) with users and hotels (this is automatically generated by a doctrine:update command) and with two columns:
user|hotela bc b
So, two different users should belong to the same hotel. But if I dump the hotel object with the users associated, the users seem to be assigned to two different hotels.
And If I render the hotels thru a JsonView, I cannot display any user (actually, there's no "users" field in it) in the Json string.
Thank you in advance for any hint!Davide
> From: christian.mueller at typo3.org
> Date: Mon, 23 Apr 2012 09:13:07 +0200
> To: flow3-general at lists.typo3.org
> Subject: Re: [FLOW3-general] Question about associations and JsonView
>
> Hi Davide,
>
> unfortunately the formatting was quite disrupted in your mail, but the
> relation annotation looks good, you can even leave the targetEntity
> information out, we fill that in anyway.
>
> If you assign your hotel to "value" in your JsonView you would want to
> have a configuration as the following:
>
> array (
> 'value' => array (
> '_descend' => array (
> 'user' => array(
> '_descentAll' => array(
> )
> )
> )
> )
>
> )
>
> Should export the assigned hotel with all users.
>
> Cheers,
> Christian
>
> --
> Christian Mueller
> TYPO3 Core Team
>
> TYPO3 .... inspiring people to share!
> Get involved: typo3.org
> _______________________________________________
> FLOW3-general mailing list
> FLOW3-general at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/flow3-general
More information about the FLOW3-general
mailing list