[FLOW3-general] Question about associations and JsonView
Davide eheheh
dmichelangeli at hotmail.com
Sat Apr 21 22:20:23 CEST 2012
Hi,I'm quite new to FLOW3/Doctrine and I would like to ask you I have 2 Classes, one is a Hotel and the other is User. Now, between the two classes there's a manytomany association: a hotel can have more users, and a user may belong to many hotels (DKM.Services is my package).
class Hotel{
.../** * @var \Doctrine\Common\Collections\Collection<\DKM\Services\Domain\Model\User> * @ORM\ManyToMany(targetEntity="DKM\Services\Domain\Model\User", mappedBy="hotels" , cascade={"persist"}) */protected $users;$users;
/** * @param \DKM\Services\Domain\Model\User $user * @return void */public function addUser(\DKM\Services\Domain\Model\User $user) { $this->users->add($user);}/** * @param \DKM\Services\Domain\Model\User $user * @return void */public function removeUser(\DKM\Services\Domain\Model\User $user) { $this->users->removeElement($user);}
public function __construct(){ $this->users = new \Doctrine\Common\Collections\ArrayCollection();}
}
class User{.../** * Hotels is an array collection of Hotel objects * @var \Doctrine\Common\Collections\ArrayCollection<\DKM\Services\Domain\Model\Hotel> * @ORM\ManyToMany(targetEntity="DKM\Services\Domain\Model\Hotel", inversedBy="users" , cascade={"persist"}) * @ORM\JoinTable(name="dkm_services_domain_model_user_hotel_join") */protected $hotels;
/** * @param \DKM\Services\Domain\Model\Hotel $hotel * @return void */public function addHotel(\DKM\Services\Domain\Model\Hotel $hotel) { $this->hotels->add($hotel);} public function __construct(){ $this->hotels = new \Doctrine\Common\Collections\ArrayCollection();}
}
Now, first question: is the manytomany association correctly set?And second question: I would like to get a hotel (with the users associated) in a JSON format, by using the JsonView class. I can get the hotel, but I don't know what should I do to get the users associated with.
Can anybody give me an advance?
Thank you very much and compliments for you work!Davide
More information about the FLOW3-general
mailing list