如何在没有关联实体的情况下检索实体?

时间:2017-01-27 16:49:11

标签: orm doctrine symfony

我的代码是

 $bars = $em->getRepository('AppBundle:Bar')->findAll();

和实体

/**
 * @var int
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
private $id;

/**
 * @var string
 *
 * @ORM\Column(name="name", type="string", length=45, nullable=true)
 */
private $name;

/**
 * @var string
 *
 * @ORM\Column(name="location", type="string", length=45, nullable=true)
 */
private $location;

/**
 * @var string
 *
 * @ORM\Column(name="zipcode", type="string", length=45, nullable=true)
 */
private $zipcode;


/**
 * @var string
 *
 * @ORM\Column(name="description", type="string", length=45, nullable=true)
 */

private $description;

/**
* @ORM\OneToMany(targetEntity="Waiter", mappedBy="bar", fetch="EXTRA_LAZY")
*/ 
protected $waiters;

/**
* @ORM\OneToMany(targetEntity="Table_", mappedBy="bar", fetch="EXTRA_LAZY")
*/ 
protected $tables;

/** @ORM\OneToMany(targetEntity="Stock_food", mappedBy="bar", fetch="EXTRA_LAZY") */

private $stockfoods;

/** @ORM\OneToMany(targetEntity="Stock_drink", mappedBy="bar", fetch="EXTRA_LAZY") */

private $stockdrinks;

我想只检索没有关联实体的条形实体(Waiter,Table_,Stock_drink,Stock_food)。

响应是所有数据,但我只需要名称,位置,邮政编码和描述。

提前致谢!!!

1 个答案:

答案 0 :(得分:0)

Helloo

我找到了解决方案!!我正在使用原始SQL查询,DBAL

    $conn = $em->getConnection();
    $sql = 'SELECT * FROM Bar';
    $stmt = $conn->prepare($sql);
    $stmt->execute();
    $bars = $stmt->fetchAll();

Thankss !!