我在Symfony存储库类中有以下DQL:
$dql = '
SELECT cg, field(cgr.channel_id, :channel) as HIDDEN field
FROM \CRMPicco\GolfBundle\Entity\CourseGuide cg
JOIN \CRMPicco\GolfBundle\Entity\CourseGuideRow cgr
WHERE cg.gender = :gender
ORDER BY cg.name ASC, field DESC
';
return $this->getEntityManager()
->createQuery($dql)
->setParameter('gender', $gender)
->setParameter('channel', $channel->getId())
->getResult();
CourseGuide
的成员变量如下所示,因此它与CourseGuideRow
之间存在关联:
/**
* @var ArrayCollection
*/
protected $rows;
CourseGuide.orm.yml
(摘要):
oneToMany:
rows:
targetEntity: CRMPicco\GolfBundle\Entity\CourseGuideRow
mappedBy: courseGuide
cascade: ["persist","remove"]
CourseGuideRow.orm.yml
(摘要):
manyToOne:
courseGuide:
targetEntity: CRMPicco\GolfBundle\Entity\CourseGuide
inversedBy: rows
joinColumn:
nullable: false
name: course_guide_id
运行此代码会给我这个错误:
[语法错误]第0行,第24行:错误:预期的已知函数,得到 '场'
简而言之,我想要实现的是使用相关的“CourseGuideRows”取出所有“CourseGuides”,并通过我传入的channel_id订购“CourseGuideRows”。例如,这可能是{{1所以我希望2
成为列表中的第一个,例如2
。