| @@ 6-45 (lines=40) @@ | ||
| 3 | namespace Entities; |
|
| 4 | ||
| 5 | /** @Entity @Table(name="addresses") */ |
|
| 6 | class Address |
|
| 7 | { |
|
| 8 | /** |
|
| 9 | * @Id @Column(type="integer") |
|
| 10 | * @GeneratedValue(strategy="AUTO") |
|
| 11 | */ |
|
| 12 | private $id; |
|
| 13 | /** @Column(type="string", length=255) */ |
|
| 14 | private $street; |
|
| 15 | /** @OneToOne(targetEntity="User", mappedBy="address") */ |
|
| 16 | private $user; |
|
| 17 | ||
| 18 | public function getId() |
|
| 19 | { |
|
| 20 | return $this->id; |
|
| 21 | } |
|
| 22 | ||
| 23 | public function getStreet() |
|
| 24 | { |
|
| 25 | return $this->street; |
|
| 26 | } |
|
| 27 | ||
| 28 | public function setStreet($street) |
|
| 29 | { |
|
| 30 | $this->street = $street; |
|
| 31 | } |
|
| 32 | ||
| 33 | public function getUser() |
|
| 34 | { |
|
| 35 | return $this->user; |
|
| 36 | } |
|
| 37 | ||
| 38 | public function setUser(User $user) |
|
| 39 | { |
|
| 40 | if ($this->user !== $user) { |
|
| 41 | $this->user = $user; |
|
| 42 | $user->setAddress($this); |
|
| 43 | } |
|
| 44 | } |
|
| 45 | } |
|
| @@ 6-48 (lines=43) @@ | ||
| 3 | namespace Entities; |
|
| 4 | ||
| 5 | /** @Entity @Table(name="users") */ |
|
| 6 | class User |
|
| 7 | { |
|
| 8 | /** |
|
| 9 | * @Id @Column(type="integer") |
|
| 10 | * @GeneratedValue(strategy="AUTO") |
|
| 11 | */ |
|
| 12 | private $id; |
|
| 13 | /** @Column(type="string", length=50) */ |
|
| 14 | private $name; |
|
| 15 | /** |
|
| 16 | * @OneToOne(targetEntity="Address", inversedBy="user") |
|
| 17 | * @JoinColumn(name="address_id", referencedColumnName="id") |
|
| 18 | */ |
|
| 19 | private $address; |
|
| 20 | ||
| 21 | public function getId() |
|
| 22 | { |
|
| 23 | return $this->id; |
|
| 24 | } |
|
| 25 | ||
| 26 | public function getName() |
|
| 27 | { |
|
| 28 | return $this->name; |
|
| 29 | } |
|
| 30 | ||
| 31 | public function setName($name) |
|
| 32 | { |
|
| 33 | $this->name = $name; |
|
| 34 | } |
|
| 35 | ||
| 36 | public function getAddress() |
|
| 37 | { |
|
| 38 | return $this->address; |
|
| 39 | } |
|
| 40 | ||
| 41 | public function setAddress(Address $address) |
|
| 42 | { |
|
| 43 | if ($this->address !== $address) { |
|
| 44 | $this->address = $address; |
|
| 45 | $address->setUser($this); |
|
| 46 | } |
|
| 47 | } |
|
| 48 | } |
|