[FLOW3-general] Question about associations and JsonView
"Christian Müller (FLOW3 Team)"
christian.mueller at typo3.org
Wed Apr 25 08:34:24 CEST 2012
Hey Davide,
could you put the code on gist or pastebin, that would make matters much
easier...
Cheers,
Christian
[1] http://gist.github.com
[2] http://pastebin.com
On 24/04/12 11:27, Davide CD wrote:
>
> 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
--
Christian Mueller
TYPO3 Core Team
TYPO3 .... inspiring people to share!
Get involved: typo3.org
More information about the FLOW3-general
mailing list