Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [Doctrine] Relacje
Vimax
post 30.06.2012, 16:19:13
Post #1





Grupa: Zarejestrowani
Postów: 4
Pomógł: 0
Dołączył: 30.06.2012

Ostrzeżenie: (0%)
-----


Witam otóż próbuje zrobić relacje, chodzi o to, żeby w encji

  1. <?php
  2. /**
  3. * @Entity
  4. * @Table(name="player_deaths")
  5. */
  6. class Entity_PlayerDeath
  7. {
  8. /**
  9. * @Id
  10. * @Column(type="integer")
  11. * @GeneratedValue(strategy="AUTO")
  12. */
  13. private $id;
  14. /** @Column(type="integer") */
  15. private $player_id;
  16. /** @Column(type="bigint") */
  17. private $date;
  18. /** @Column(type="integer") */
  19. private $level;
  20.  
  21. public function setId($id) {
  22. $this->id = $id;
  23. return $this;
  24. }
  25.  
  26. public function getId() {
  27. return $this->id;
  28. }
  29.  
  30. public function setPlayerId($player_id) {
  31. $this->player_id = $player_id;
  32. return $this;
  33. }
  34.  
  35. public function getPlayerId() {
  36. return $this->player_id;
  37. }
  38.  
  39. public function setDate($date) {
  40. $this->date = $date;
  41. return $this;
  42. }
  43.  
  44. public function getDate() {
  45. return $this->date;
  46. }
  47.  
  48. public function setLevel($level) {
  49. $this->level = $level;
  50. return $this;
  51. }
  52.  
  53. public function getLevel() {
  54. return $this->level;
  55. }
  56. }


pojawilo się name z

  1. <?php
  2. /**
  3. * @Entity
  4. * @Table(name="players")
  5. */
  6. class Entity_Player
  7. {
  8. /**
  9. * @Id
  10. * @Column(type="integer")
  11. * @GeneratedValue(strategy="AUTO")
  12. */
  13. private $id;
  14. /** @Column(type="string") */
  15. private $name;


Próbowałem w taki sposób:
  1. /*
  2.   * @OneToOne(targetEntity="Entity_Player")
  3.   * @JoinColumn(name="player_id", referencedColumnName="id")
  4.   */
  5. private $player;


ale i tak zwracało $player zwracało null.

Jak to ma wyglądać?
Go to the top of the page
+Quote Post
Necsord
post 30.06.2012, 17:48:05
Post #2





Grupa: Zarejestrowani
Postów: 189
Pomógł: 60
Dołączył: 5.10.2010
Skąd: Bydgoszcz

Ostrzeżenie: (0%)
-----


Wyglada poprawnie na pierwszy rzut oka. Sprawdziłeś dokładnie czy od strony bazy nie ma problemów?

  1. /*
  2.  * @OneToOne(targetEntity="Entity_Player")
  3.  * @JoinColumn(name="player_id", referencedColumnName="id")
  4.  */
  5. private $player;

Dokładnie tak próbowałeś ? Początek PHPDoc'a jest niepoprawny, powinno byc "/**".
Go to the top of the page
+Quote Post
Vimax
post 30.06.2012, 18:31:39
Post #3





Grupa: Zarejestrowani
Postów: 4
Pomógł: 0
Dołączył: 30.06.2012

Ostrzeżenie: (0%)
-----


Fakt, literówka, musze sobie wbić do głowy, że /** a nie /* w końcu ;p

Ale i tak jest problem, gdy tak zrobiłem to pluje blędami typu:
require(C:\wamp\www\axam/application/models/Proxies\__CG__Entity_Player.php

Wszystkie modele encji znajdują sie w application/models/entity i czemu __CG__ ?

Nie wiem czemu w ogóle Proxy, ale może coś tutaj źle:
  1. $config->setProxyDir(APPLICATION_PATH . '/models/Proxies');
  2. $config->setAutoGenerateProxyClasses(true);
  3. $config->setProxyNamespace('App\Proxies');
Go to the top of the page
+Quote Post
Necsord
post 30.06.2012, 19:15:13
Post #4





Grupa: Zarejestrowani
Postów: 189
Pomógł: 60
Dołączył: 5.10.2010
Skąd: Bydgoszcz

Ostrzeżenie: (0%)
-----


Niedawno dopiero zacząłem z doctrine, ale te klasy są generowane automatycznie, aby dodac funkcjonalności twoim powiązanym klasom. Tak czy inaczej sprawdź czy plik sie generuje / czy folder istnieje / czy doctrine ma możliwosc generowania tych klas.

Ten post edytował Necsord 30.06.2012, 19:15:40
Go to the top of the page
+Quote Post
Vimax
post 3.07.2012, 15:43:44
Post #5





Grupa: Zarejestrowani
Postów: 4
Pomógł: 0
Dołączył: 30.06.2012

Ostrzeżenie: (0%)
-----


Okej, dzięki, działa. Zapomniałem stworzyć folder wink.gif

Jeszcze żeby nie tworzyć nowego folderu, jak zrobić aby pobierało jedno pole a nie wszystkie z tabeli?

Próbowałem

  1.  
  2. /**
  3.   * @OneToOne(targetEntity="Entity_Player")
  4.   * @JoinColumn(name="player_id", referencedColumnName="id", fieldName="name")
  5.   */


Ale nie działa i dalej zwraca cały obiekt. Da sie w ogóle coś takiego w doctrine?

Ten post edytował Vimax 3.07.2012, 15:44:02
Go to the top of the page
+Quote Post
Crozin
post 3.07.2012, 15:48:25
Post #6





Grupa: Zarejestrowani
Postów: 6 476
Pomógł: 1306
Dołączył: 6.08.2006
Skąd: Kraków

Ostrzeżenie: (0%)
-----


Takie coś określa się już na poziomie DQL-a, nie konfiguracji Doctrine.
  1. SELECT o1, o2.{field_a, field_b} FROM Object1 o1 JOIN Object2 o2
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 19.07.2025 - 17:35