Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- //This is necessary (I don't know if there's a way to automatically do this)
- //because user is the "inversedSide" of the manytomany relationship.
- //@see http://docs.doctrine-project.org/projects/doctrine-orm/en/2.0.x/reference/association-mapping.html#association-mapping-owning-inverse
- foreach ($hotels as $hotel) {
- $hotel->getUsers()->add($this);
- }
- }
- }
- 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;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment