加入 table 无实体主义

Join table in Doctrine without Entity

我有一个我无法解决的问题。 我有一个实体,我正在尝试加入 table:

 /**
     * @var ArrayCollection
     *
     * @ORM\ManyToMany(targetEntity="FeaturedAttribute")
     * @ORM\JoinTable(name="property_featured_attribute",
     *     joinColumns={@ORM\JoinColumn(name="property", referencedColumnName="id")},
     *     inverseJoinColumns={@ORM\JoinColumn(name="featured_property", referencedColumnName="id")})
     */

我需要在我的 DQL 代码中使用名称 property_featured_attribute 加入 table table:

LEFT JOIN property_featured_attribute pfa WITH pfa.property = p.id
WHERE pfa.featured_property IN (:attrs)

问题是,这个 table - property_featured_attribute - 没有实体,所以我收到如下错误:

'Error: Class 'property_featured_attribute' is not defined.'

是否可以在我的 DQL 查询中加入没有实体的 table?

您不能使用 DQL 执行此操作,因为 DQL 的目的是对您的对象模型进行查询。 DQL 是对象模型的查询语言,而不是关系模式的查询语言。

但您可以使用 DBAL 进行简单查询:

$conn = $this->get('database_connection');
$res = $conn->query('SELECT...');