use*_*085 5 orm doctrine symfony doctrine-orm
我的项目中有以下实体结构.
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;
}
Run Code Online (Sandbox Code Playgroud)
当我试图使用Doctrine中的findby()函数获取"$ example"时,我收到了以下通知:
未定义的索引:joinColumns
我试图调试它,问题似乎是在函数的教义文件BasicEntityPersister.php中
_getSelectEntitiesSQL($criteria, $assoc = null, $lockMode = 0, $limit = null, $offset = null, array $orderBy = null),
Run Code Online (Sandbox Code Playgroud)
我在堆栈跟踪中观察到第二个参数"$ assoc"始终为null,我认为这就是Doctrine不生成JOIN语句的原因.
任何的想法?
谢谢
我相信这是一个错误,可能是这个。
我有同样的问题,现在唯一的解决方案似乎是等待 BasicEntityPersister 的更新或编写非常简单的查询。
首先将存储库添加到您的类中
/**
* MyClass
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="Acme\DemoBundle\Entity\MyClassRepository")
*/
class MyClass
...
Run Code Online (Sandbox Code Playgroud)
然后在你的存储库类中:
class MyClassRepository extends EntityRepository
{
public function findByExample( Example $example )
{
return $this->getEntityManager()
->createQueryBuilder()
->select('m')
->from('AcmeDemoBundle:MyClass', 'm')
->innerJoin('m.examples', 'e')
->where('e.id = :exampleid' )
->setParameter('exampleid', $example->getId() )
->getQuery()
->getResult();
}
}
Run Code Online (Sandbox Code Playgroud)
最后你可以通过以下方式获取与Example相关的所有MyClass实例:
$this->getDoctrine()->getManager()->getRepository('AcmeDemoBundle:MyClass')->findByExample( $example );
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3446 次 |
| 最近记录: |