Guest User

Untitled

a guest
Jul 12th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Entities;
  4.  
  5. use \Doctrine\Common\Collections\ArrayCollection, Entities\Feature;
  6.  
  7. /**
  8. * @Entity
  9. * @Table(name="products")
  10. */
  11. class Product {
  12. /**
  13. * @Id @Column(type="integer")
  14. * @GeneratedValue(strategy="AUTO")
  15. */
  16. private $id;
  17.  
  18. /**
  19. * @ManyToMany(targetEntity="Feature", cascade={"persist"})
  20. * @JoinTable(
  21. * name="product_features",
  22. * joinColumns={@JoinColumn(name="product_id", referencedColumnName="id")},
  23. * inverseJoinColumns={@JoinColumn(name="feature_id", referencedColumnName="id")}
  24. * )
  25. */
  26. private $features;
  27.  
  28. public function __construct()
  29. {
  30. $this->features = new ArrayCollection;
  31. }
  32.  
  33. public function getId()
  34. {
  35. return $this->id;
  36. }
  37.  
  38. public function addFeature(Feature $feature)
  39. {
  40. if (!$this->features->contains($feature))
  41. {
  42. $this->features->add($feature);
  43. $feature->addProduct($this);
  44. }
  45. }
  46.  
  47. public function getFeatures()
  48. {
  49. return $this->features;
  50. }
  51. }
Add Comment
Please, Sign In to add comment