【发布时间】:2013-08-20 09:15:05
【问题描述】:
我的项目中有以下实体结构。
class MyEntity
{
[... some more fields...]
/**
* @Type("array<string, string>")
* @ORM\ManyToMany(targetEntity="Me\MyBundle\Entity\Example")
* @ORM\JoinTable(name="example_myentity",
* joinColumns={@ORM\JoinColumn(name="plan_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="example", referencedColumnName="label")}
* )
*/
private $example;
}
class Example
{
/**
* @ORM\Id
* @ORM\Column(name="label", type="string", length=50, unique=true, nullable=false)
*/
private $label;
}
当我尝试使用 Doctrine 中的 findby() 函数获取“$example”时,我收到以下通知:
未定义索引:joinColumns
我尝试调试了一下,问题似乎出在函数中的学说文件BasicEntityPersister.php中
_getSelectEntitiesSQL($criteria, $assoc = null, $lockMode = 0, $limit = null, $offset = null, array $orderBy = null),
我在堆栈跟踪中观察到第二个参数“$assoc”总是为空,我认为这就是为什么 Doctrine 没有做出 JOIN 语句的原因。
有什么想法吗?
谢谢
【问题讨论】:
-
你更新数据库了吗?
-
是的,它都是最新的。数据库已更新,缓存已清除...
-
如果是多对多,那么 MyEntity.$example 不应该是 $examples 吗?您是否在构造函数中将其初始化为教义数组? docs.doctrine-project.org/projects/doctrine-orm/en/latest/…
-
是的,我在构造函数中将它初始化为一个学说数组,例如当我获取 MyEntity 列表时,我得到所有参数都没有问题,问题是当我尝试过滤它时。
标签: symfony orm doctrine-orm doctrine