我有这个具有以下字段的实体:
Andrei\StatisticsBundle\Entity\Visit:
type: entity
table: visits
id:
id:
type: integer
generator: { strategy: AUTO }
fields:
counter:
type: integer
createdAt:
type: datetime
column: created_at
manyToOne:
visitor:
targetEntity: Andrei\StatisticsBundle\Entity\Visitor
inversedBy: visits
joinColumn:
name: visitor_id
referencedColumnName: id
website:
targetEntity: Andrei\StatisticsBundle\Entity\Website
inversedBy: visits
joinColumn:
name: website_id
referencedColumnName: id
country:
targetEntity: Andrei\StatisticsBundle\Entity\Country
inversedBy: visits
joinColumn:
name: country_id
referencedColumnName: id
我想执行一个简单的选择条件并为 website_id 数据库列添加一个位置,如下所示,但它不起作用。我相信 website_id 现在被视为访问实体的字段,它是网站对象的属性,但我看不出如何进行这些类型的查询:
$em = $this->getDoctrine()->getManager();
$repository = $em->getRepository('AndreiStatisticsBundle:Visit');
$qb = $repository->createQueryBuilder('v')
->select('SUM(v.counter) AS views, v.createdAt AS day')
->where('v.website.id = :website_id')
->setParameter('website_id', 3)
->groupBy('v.createdAt');
$visits = $qb->getQuery()->getScalarResult();