Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [doctrine2] mapowanie
wtk13
post
Post #1





Grupa: Zarejestrowani
Postów: 2
Pomógł: 0
Dołączył: 6.07.2015

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


Witam, mam pytanie dotyczące mapowania. Mam 3 entity Page, Gallery i File Czy możliwe jest mapowanie przy użyciu klucza? Np. dla Page chce wyciągnąć file po entity_id i po entity_type = 'page', dla Gallery po entity_type = 'gallery'. Zacząłem tworzyć te entity i zatrzymałem się na tym problemie. Proszę o pomoc.

File:

  1. **
  2. * @ORM\Entity
  3. * @ORM\Table(name="cms_file")
  4. */
  5. class File
  6. {
  7. /**
  8.  * @ORM\Id
  9.  * @ORM\GeneratedValue(strategy="AUTO")
  10.  * @ORM\Column(type="integer")
  11.  */
  12. protected $id;
  13.  
  14. /** @ORM\Column(type="string") */
  15. protected $entity_type;
  16.  
  17. /** @ORM\Column(type="integer") */
  18. protected $entity_id;
  19.  
  20. /** @ORM\Column(type="text") */
  21. protected $filename;
  22.  
  23. /** @ORM\Column(type="string") */
  24. protected $mime_type;
  25.  
  26. /**
  27.  * @ORM\ManyToOne(targetEntity="CmsIr\File\Entity\Gallery", inversedBy="entity_id")
  28.  * @ORM\JoinColumn(name="entity_id", referencedColumnName="id", onDelete="CASCADE")
  29.  **/
  30. protected $gallery;
  31.  
  32. /**
  33. * @ORM\ManyToOne(targetEntity="CmsIr\Page\Entity\Page", inversedBy="entity_id")
  34. * @ORM\JoinColumn(name="entity_id", referencedColumnName="id", onDelete="CASCADE")
  35. **/
  36. protected $page;


Page:

  1. /**
  2. * @ORM\Entity(repositoryClass="CmsIr\Page\Entity\PageTable")
  3. * @ORM\Table(name="cms_page")
  4. */
  5. class Page
  6. {
  7. /**
  8.  * @ORM\Id
  9.  * @ORM\GeneratedValue(strategy="AUTO")
  10.  * @ORM\Column(type="integer")
  11.  */
  12. protected $id;
  13.  
  14. /** @ORM\Column(type="string") */
  15. protected $name;
  16.  
  17. /** @ORM\Column(type="string") */
  18. protected $slug;
  19.  
  20. /** @ORM\Column(type="string") */
  21. protected $url;
  22.  
  23. /**
  24. * @ORM\ManyToOne(targetEntity="CmsIr\System\Entity\Status")
  25. * @ORM\JoinColumn(name="status_id", referencedColumnName="id")
  26. */
  27. protected $status;
  28.  
  29. /** @ORM\Column(type="text") */
  30. protected $content;
  31.  
  32. /** @ORM\Column(type="string") */
  33. protected $filename_main;
  34.  
  35. /**
  36.  * @ORM\OneToMany(targetEntity="CmsIr\File\Entity\File", mappedBy="page")
  37.  **/
  38. protected $files;
  39.  
  40. public function __construct()
  41. {
  42. $this->files = new ArrayCollection();
  43. }


Gallery:

  1. /**
  2. * @ORM\Entity(repositoryClass="CmsIr\File\Entity\GalleryTable")
  3. * @ORM\Table(name="cms_gallery")
  4. */
  5. class Gallery
  6. {
  7. /**
  8.  * @ORM\Id
  9.  * @ORM\GeneratedValue(strategy="AUTO")
  10.  * @ORM\Column(type="integer")
  11.  */
  12. protected $id;
  13.  
  14. /**
  15.  * @ORM\ManyToOne(targetEntity="CmsIr\System\Entity\Status")
  16.  * @ORM\JoinColumn(name="status_id", referencedColumnName="id")
  17.  */
  18. protected $status;
  19.  
  20. /** @ORM\Column(type="string") */
  21. protected $name;
  22.  
  23. /** @ORM\Column(type="text") */
  24. protected $slug;
  25.  
  26. /** @ORM\Column(type="string") */
  27. protected $url;
  28.  
  29. /**
  30.  * @ORM\OneToMany(targetEntity="CmsIr\File\Entity\File", mappedBy="gallery")
  31.  **/
  32. protected $files;
  33.  
  34. public function __construct()
  35. {
  36. $this->files = new ArrayCollection();
  37. }
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 23.12.2025 - 23:13