View difference between Paste ID: 3vNvUQhc and i1QwgWNQ
SHOW: | | - or go back to the newest paste.
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
71+
Davide
72
73
I have found after many tries the solution (data is the "value"):
74
75
'data' => array(
76
	'_descendAll' => array(
77
	'_exposeObjectIdentifier' => true,
78
	'_only' => $this->exposeFields,
79
	'_descend' => array(
80
		'users' => array(
81
			'_descendAll' => array(
82
				'_exposeObjectIdentifier' => true,
83
				'_only' => array('__identity')
84
			),
85
		),
86
	),
87
)