Guest User

FLOW3 Association and JsonView

a guest
Apr 25th, 2012
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.84 KB | None | 0 0
  1. class Hotel{
  2. /**
  3. * Users is an array collection of User objects
  4. * @var \Doctrine\Common\Collections\Collection<\DKM\Services\Domain\Model\User>
  5. * @ORM\ManyToMany(inversedBy="hotels" , cascade={"persist"})
  6. * @ORM\JoinTable(name="dkm_services_domain_model_hotel_user_join")
  7. */
  8. protected $users;
  9.  
  10. /**
  11. * Get the Hotel's users
  12. *
  13. * @return \Doctrine\Common\Collections\Collection The Hotel's users
  14. */
  15. public function getUsers() {
  16.  return $this->users;
  17. }
  18. /**
  19.  * Sets this Hotel's users
  20.  *
  21.  * @param \Doctrine\Common\Collections\Collection $users The Hotel's users
  22.  * @return void
  23.  */
  24. public function setUsers(\Doctrine\Common\Collections\Collection $users) {
  25.     $this->users = $users;
  26. }
  27.  
  28. }
  29.  
  30. class User{
  31.  
  32. /**
  33.      * @var \Doctrine\Common\Collections\Collection<\DKM\Services\Domain\Model\Hotel>
  34.      * @ORM\ManyToMany(mappedBy="users" , cascade={"persist"})
  35.      */
  36.     protected $hotels;
  37.    
  38. /**
  39.      * Get the Users's hotels
  40.      *
  41.      * @return \Doctrine\Common\Collections\Collection The Users's hotels
  42.      */
  43.     public function getHotels() {
  44.         return $this->hotels;
  45.     }
  46.  
  47.     /**
  48.      * Sets this User's hotel
  49.      *
  50.      * @param \Doctrine\Common\Collections\Collection $users The User's hotels
  51.      * @return void
  52.      */
  53.     public function setHotels(\Doctrine\Common\Collections\Collection $hotels) {
  54.         $this->hotels = $hotels;
  55.     }
  56.    
  57.  
  58. }
  59.  
  60. I have an association table (jointable) with users and hotels (this is automatically generated by a doctrine:update command) and with two columns:
  61.  
  62. user|hotel
  63. a      b
  64. c      b
  65.  
  66. 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.
  67.  
  68. And If I render the hotels thru a JsonView, I cannot display any user (actually, there's no "users" data in it) in the Json string.
  69.  
  70. Thank you in advance for any hint!
  71. Davide
Advertisement
Add Comment
Please, Sign In to add comment