【发布时间】:2019-01-25 12:59:12
【问题描述】:
我正在 Doctrine 中设置一个新数据库,我想使用 Many-To-One 关系。
数据库运行良好,但我无法对这些类使用查询。
我遵循了这些文档:
/**
* @Entity @Table
**/
class Section
{
/**
* @Id @Column(type="integer") @GeneratedValue
**/
protected $id;
//...
/**
* @ManyToOne(targetEntity="Manufacturer")
*/
private $manufacturer;
//...
}
/**
* @Entity
**/
class Manufacturer
{
/**
* @Id @Column(type="integer") @GeneratedValue
**/
protected $id;
//...
}
所以我的问题是,我不能对Section 使用任何查询。
为了测试,我有这个小程序:
$relation = 'Section';
$rep = $entityManager->getRepository($relation); //here is the problem
$result = $rep->findAll();
foreach ($result as $row) {
echo $row->getName();
}
如果我将$relation 更改为'Manufacturer' 它正在工作,或者如果我使用另一个关系(One-To-One 或Many-To-Many),它也很好。但我不能使用Many-To-One(或One-To-Many bidirectional)。
手动 DQL 查询不起作用。
我在这个问题上坐了两天多,希望你能帮助我。
【问题讨论】: