Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [Symfony]Problem self-referncing
Marys91
post 10.11.2012, 14:00:56
Post #1





Grupa: Zarejestrowani
Postów: 45
Pomógł: 0
Dołączył: 29.12.2010

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


Witam,
mam problem z głupimy kategoriami, a mianowicie stworzyłem sobie już wszystko i teraz próbuje ustawić relacje tak, żeby wstawiać podkategorię. Jak ustawiłem sobie relacje i zrobiłem schema update to znikła mi jedna kolumna. Szukam Szukam i nic nie mogę znaleźć.
Dobra to może jeszcze powiem dokładnie co chce osiągnąć.
Chce zrobić sobie taką tabelkę:
id | name | parent_id

i mam już taką klasę w entity:
  1. class Categories
  2. {
  3. /**
  4.   * @var integer $id
  5.   *
  6.   * @ORM\Column(name="id", type="integer")
  7.   * @ORM\Id
  8.   * @ORM\GeneratedValue(strategy="AUTO")
  9.   */
  10. private $id;
  11.  
  12. /**
  13.   * @var string $name
  14.   *
  15.   * @ORM\Column(name="name", type="string", length=255)
  16.   */
  17. private $name;
  18.  
  19. /*
  20.   * @var PrivateBusiness\BackendBundle:Categories
  21.   *
  22.   * @ORM\OneToMany(targetEntity="Categories", mappedBy="parent_id")
  23.   * @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
  24.   */
  25. private $children;
  26.  
  27. /*
  28.   * @var integer $parent_id
  29.   *
  30.   * @ORM\Column(name="parent_id", type="integer")
  31.   *
  32.   *
  33.   * @ORM\ManyToOne(targetEntity="Categories", inversedBy="children")
  34.   */
  35. private $parent_id;
  36.  
  37.  
  38.  
  39. public function __construct() {
  40. $this->children = new \Doctrine\Common\Collections\ArrayCollection();
  41. }
  42.  
  43.  
  44. /**
  45.   * Get id
  46.   *
  47.   * @return integer
  48.   */
  49. public function getId()
  50. {
  51. return $this->id;
  52. }
  53.  
  54. /**
  55.   * Set name
  56.   *
  57.   * @param string $name
  58.   * @return Categories
  59.   */
  60. public function setName($name)
  61. {
  62. $this->name = $name;
  63.  
  64. return $this;
  65. }
  66.  
  67. /**
  68.   * Get name
  69.   *
  70.   * @return string
  71.   */
  72. public function getName()
  73. {
  74. return $this->name;
  75. }
  76.  
  77. /**
  78.   * Set parent
  79.   *
  80.   * @param integer $parent
  81.   * @return Categories
  82.   */
  83. public function setParent_id($parent)
  84. {
  85. $this->parent_id = $parent;
  86.  
  87. return $this;
  88. }
  89.  
  90. /**
  91.   * Get parent
  92.   *
  93.   * @return integer
  94.   */
  95. public function getParent_id()
  96. {
  97. return $this->parent_id;
  98. }
  99.  
  100. public function setChildren($child){
  101. $this->child = $child;
  102.  
  103. return $this;
  104. }
  105.  
  106. public function getChildren(){
  107. return $this->child;
  108. }
  109.  
  110. public function __toString() {
  111. return $this->getName();
  112. }
  113. }
  114.  


Problem w tym, że symfony generuje mi tylko kolumny id oraz name, a jak zrobiłem tabele ręcznie to nie dodaje mi parent.
Go to the top of the page
+Quote Post
Crozin
post 10.11.2012, 14:26:13
Post #2





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

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


1. Przecież to nie ma żadnego związku z Symfony.
2. Nazwą klasy powinno być raczej Category.
3. Model obiektowy nie jest tożsamy z modelem w bazie danych. Takich potworków jak parent_id nie ma prawa tutaj być.
4. http://docs.doctrine-project.org/projects/...elf-referencing
Go to the top of the page
+Quote Post
Marys91
post 10.11.2012, 14:40:14
Post #3





Grupa: Zarejestrowani
Postów: 45
Pomógł: 0
Dołączył: 29.12.2010

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


Jak nie ma żadnego związku z Symfony? Projekt jest w Symfony, normalnie działa a w Symfony nie działa. Dobra nie ważne już chyba sobie poradziłem, wyrzuciłem wszystko i wpisałem jeszcze raz. Nie wiem gdzie był problem.
Go to the top of the page
+Quote Post
szok
post 10.11.2012, 20:11:16
Post #4





Grupa: Zarejestrowani
Postów: 165
Pomógł: 20
Dołączył: 2.03.2006

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


Może tutaj:

  1. * @ORM\Column(name="parent_id", type="integer")
  2. *
  3. *
  4. * @ORM\ManyToOne(targetEntity="Categories", inversedBy="children")
  5. */

Zamiast:
  1. * @ORM\Column(name="parent_id", type="integer")
  2. * @ORM\ManyToOne(targetEntity="Categories", inversedBy="children")
  3. */


Może Symfony nie przerobiło tego bo były entery między tym?
Tak strzelam, ale zobacz swój aktualny kod, czy to się tym nie różni?


--------------------
Go to the top of the page
+Quote Post
misi3kk
post 11.11.2012, 15:33:06
Post #5





Grupa: Zarejestrowani
Postów: 26
Pomógł: 4
Dołączył: 14.05.2010

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


Błąd był na pewno w komentarzu.

Wymagane jest, aby komentarz z adnotacjami zaczynał się od "/**" - koniecznie, "/*" nie zadziała.


--------------------
Accesto.pl
Go to the top of the page
+Quote Post
Marys91
post 13.11.2012, 05:58:00
Post #6





Grupa: Zarejestrowani
Postów: 45
Pomógł: 0
Dołączył: 29.12.2010

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


Dobra chyba był błąd w tych całych komentarzach. Dzięki wielkie za pomoc.
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: 27.04.2024 - 00:00