Bond.php 988B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace Doctrine\Tests\Models\StockExchange;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. /**
  5. * Bonds have many stocks. This uses a many to many assocation and fails to model how many of a
  6. * particular stock a bond has. But i Need a many-to-many assocation, so please bear with my modelling skills ;)
  7. *
  8. * @Entity
  9. * @Table(name="exchange_bonds")
  10. */
  11. class Bond
  12. {
  13. /**
  14. * @Id @GeneratedValue @column(type="integer")
  15. * @var int
  16. */
  17. private $id;
  18. /**
  19. * @column(type="string")
  20. * @var string
  21. */
  22. private $name;
  23. /**
  24. * @ManyToMany(targetEntity="Stock", indexBy="symbol")
  25. * @JoinTable(name="exchange_bonds_stocks")
  26. * @var Stock[]
  27. */
  28. public $stocks;
  29. public function __construct($name)
  30. {
  31. $this->name = $name;
  32. }
  33. public function getId()
  34. {
  35. return $this->id;
  36. }
  37. public function addStock(Stock $stock)
  38. {
  39. $this->stocks[$stock->getSymbol()] = $stock;
  40. }
  41. }