There are 2 tables.
<?php namespace DCS\Entity; /** * DCS\Entity\DcsSpectators * * @Table(name="dcs_spectators") * @Entity */ class DcsSpectators { /** * @var integer $id * * @Column(name="id", type="integer", precision=0, scale=0, nullable=false, unique=false) * @Id * @GeneratedValue(strategy="AUTO") */ private $id; /** * @var integer $pilotId * @Column(name="pilot_id", type="integer", precision=0, scale=0, nullable=false, unique=false) */ private $pilotId; This table stores references (pilot_id) to another table (foreign key).
The second table is a list of pilots.
<?php namespace DCS\Entity; /** * * * @Table(name="pilots") * @Entity * */ class Pilots { /** * @var integer $id * @Column(name="id", type="integer", precision=0, scale=0, nullable=false, unique=false) * @Id * @GeneratedValue(strategy="IDENTITY") */ private $id; /** * @var string $nickname * * @Column(name="nickname", type="string", length=128, precision=0, scale=0, nullable=false, unique=false) */ private $nickname; How to correctly write in the annotations of the relationship between these tables? Tried different methods, nothing works.
Zend Framework 1.12.17.
<?php class IndexController extends Zend_Controller_Action { public function init() { $this->doctrine = Zend_Registry::get('doctrine'); $this->entityManager = $this->doctrine->getEntityManager(); } public function indexAction() { $pilots = new DCS\Entity\Pilots(); $red = new DCS\Entity\DcsRedteam(); $blue = new DCS\Entity\DcsBlueteam(); $spectators = $this->entityManager->getRepository('DCS\Entity\DcsSpectators')->findAll(); foreach($spectators as $spectator){ echo "<pre>"; var_dump($spectator); } $info = $pilots->getMainPageInfo($this->entityManager); $redteam = $red->getList($this->entityManager); $blueteam = $blue->getList($this->entityManager); $this->view->redteam = $redteam; $this->view->blueteam = $blueteam; $this->view->flight_players = $info; } } After executing this code, I get an array of Spectators, but ... data from another Pilots table will not be joined either via Inner or via Left join. I don’t want to write a query through createQuery, I don’t want to do the same via queryBuilder.
As a result, I want to get all the records from the DCS_Spectators table and the attached Pilots.nickname field from the 2nd table.
How correctly to register in the annotations of classes of communication between these tables in Doctrine 2? How can I debug Entities? That is, when I use the method getRepository('Entity') - I call the method findAll() - I would like to keep track of which SELECT query is generated.
Thank.