Answer the question
In order to leave comments, you need to log in
How to display results from linked table?
I have a table:
/**
* Fcsnotificationea
*
* @ORM\Table(name="fcsNotificationEA")
* @ORM\Entity
*/
class Fcsnotificationea
{
...
/**
* @ORM\OneToMany(targetEntity="Attachmentstoea", mappedBy="Fcsnotificationea")
**/
private $attachments;
...
/**
* Constructor
*/
public function __construct()
{
$this->attachments = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Add attachment
*
* @param \Custom\ScanFilesBundle\Entity\Attachmentstoea $attachment
*
* @return Fcsnotificationea
*/
public function addAttachment(\Custom\ScanFilesBundle\Entity\Attachmentstoea $attachment)
{
$this->attachments[] = $attachment;
return $this;
}
/**
* Remove attachment
*
* @param \Custom\ScanFilesBundle\Entity\Attachmentstoea $attachment
*/
public function removeAttachment(\Custom\ScanFilesBundle\Entity\Attachmentstoea $attachment)
{
$this->attachments->removeElement($attachment);
}
/**
* Get attachments
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getAttachments()
{
return $this->attachments;
}
/**
* Attachmentstoea
*
* @ORM\Table(name="attachmentsToEA", indexes={@ORM\Index(name="notificationEAid", columns={"notificationEAid", "id"}), @ORM\Index(name="IDX_5637D788CEB3C986", columns={"notificationEAid"})})
* @ORM\Entity
*/
class Attachmentstoea
{
...
/**
* @var \Fcsnotificationea
*
* @ORM\ManyToOne(targetEntity="Fcsnotificationea")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="notificationEAid", referencedColumnName="id")
* })
*/
private $notificationeaid;
...
/**
* Add attachment
*
* @param \Custom\ScanFilesBundle\Entity\Attachmentstoea $attachment
*
* @return Fcsnotificationea
*/
public function addAttachment(\Custom\ScanFilesBundle\Entity\Attachmentstoea $attachment)
{
$this->attachments[] = $attachment;
return $this;
}
$eaNotification->addAttachment($eaAttachments);
/**
* Get attachments
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getAttachments()
{
return $this->attachments;
}
{% for notification in notificationsEA %}
{% for attach in notification.getAttachments %}
$twig_params["notificationsEA"] = $em->createQueryBuilder()
->select('n')
->from('CustomScanFilesBundle:Fcsnotificationea', 'n')
->setFirstResult($page)
->setMaxResults(10)
->join('CustomScanFilesBundle:Attachmentstoea', 'a',
\Doctrine\ORM\Query\Expr\Join::WITH, 'n.id = a.notificationeaid')
->getQuery()
->getResult();
Answer the question
In order to leave comments, you need to log in
class Fcsnotificationea
{
/**
* @ORM\OneToMany(targetEntity="Attachmentstoea", mappedBy="Fcsnotificationea")
**/
private $attachments;
I have a table:
$notification = new FcsNotificationEA();
// добавляем 3 аттачмента
$notification->add(new Attachment());
$notification->add(new Attachment());
$notification->add(new Attachment());
$this->notificationsRepository->add($notification); // внутри add происходит persist
$this->get('doctrine.orm.entity_manager')->flush(); // коммитим изменения в базу
return $this->render('some_template.twig', compact('notification'));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question