从多对多表获取



>我正在尝试从mysql表中
获取结果我正在使用symfony3,当然还有教义2
我有 2 个实体客户端.php

<?php
namespace AppBundleEntity;
use DoctrineORMMapping as ORM;
use DoctrineORMMappingManyToMany;
use DoctrineORMMappingJoinTable;
use DoctrineORMMappingJoinColumn;
/**
 * Client
 *
 * @ORMTable(name="client")
 * @ORMEntity(repositoryClass="AppBundleRepositoryClientRepository")
 */
class Client
{
    /**
     * @var int
     *
     * @ORMColumn(name="id", type="integer")
     * @ORMId
     * @ORMGeneratedValue(strategy="AUTO")
     */
    private $id;
    /**
     * @var int
     *
     * @ORMColumn(name="cin", type="integer")
     */
    private $cin;
    /**
    * @ManyToMany(targetEntity="
    * @JoinTable(name="listesouhait",
    * joinColumns={@JoinColumn(name="utilisateur_id", 
    referencedColumnName="id")},
     * inverseJoinColumns={@JoinColumn(name="evenement_id", 
    referencedColumnName="id")}
     *      )
     */
    private $evenements;
    public function __construct() {
        $this->groups = new DoctrineCommonCollectionsArrayCollection();
    }
    /**
     * Get id
     *
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }
    /**
     * Set cin
     *
     * @param integer $cin
     *
     * @return Client
     */
    public function setCin($cin)
    {
        $this->cin = $cin;
        return $this;
    }
    /**
     * Get cin
     *
     * @return int
     */
    public function getCin()
    {
        return $this->cin;
    }
    /**
     * Add evenement
     *
     * @param AppBundleEntityEvenement $evenement
     *
     * @return Client
     */
    public function addEvenement(AppBundleEntityEvenement $evenement)
    {
        $this->evenements[] = $evenement;
        return $this;
    }
    /**
     * Remove evenement
     *
     * @param AppBundleEntityEvenement $evenement
     */
    public function removeEvenement(AppBundleEntityEvenement $evenement)
    {
        $this->evenements->removeElement($evenement);
    }
    /**
     * Get evenements
     *
     * @return DoctrineCommonCollectionsCollection
     */
    public function getEvenements()
    {
        return $this->evenements;
    }
}

和埃文门特.php

<?php
namespace AppBundleEntity;
use DoctrineORMMapping as ORM;
use DoctrineORMMappingManyToOne;
use DoctrineORMMappingJoinColumn;
/**
* Evenement
*
* @ORMTable(name="evenement")
* @ORMEntity(repositoryClass="AppBundleRepositoryEvenementRepository")
*/
class Evenement
{
    /**
     * @var int
     *
     * @ORMColumn(name="id", type="integer")
     * @ORMId
     * @ORMGeneratedValue(strategy="AUTO")
     */
    private $id;
    //all attributes

执行 PHP bin\console 原则时:模式:更新 --force
图片来源
现在一切都很好
但是我找不到一个清晰的代码来插入我的控制器操作以获取表列表中的所有记录(这是自动生成的(,因为表列表houhait不是真正的实体
还要提到我的存储库是空的
我听说过存储库中的 DQL,它可能会有所帮助
所以可以帮我吗?

要获取附加到客户端的事件列表,请在控制器中:

$em = $this->getDoctrine()->getManager();
// Récupérer le client qui a l'id = 1
$item = $em->getRepository('AppBundle:Client')->findOneById(1);
// Liste des evenements 
$events = $item->getEvenements();
foreach ($events as $event)
{
    echo $event->getId() .'<br>';
}
die;

相关内容

  • 没有找到相关文章