我有实体
mhBTBundleEntityPost:
type: entity
table: post
repositoryClass: mhBTBundleRepositoryPostRepository
fields:
id:
id: true
type: integer
unsigned: true
nullable: false
generator:
strategy: IDENTITY
title:
type: string
length: 255
nullable: false
content:
type: text
nullable: false
isModered:
type: boolean
nullable: false
isPublished:
type: boolean
nullable: false
pubDate:
type: datetime
nullable: false
现在在1分钟的cron呼叫脚本中一次,如果POST具有ISMODERED = true and PubDate<:现在。
$this->getEM()->createQueryBuilder()
->update('BTBundle:Post p')
->set('p.isPublished', 'true')
->where('p.pubDate < :date AND p.isModered = true')
->setParameter(':date', new DateTime())
->getQuery()->execute();
但是,如果SQL(p.pubDate < CURDATE() AND p.isModered = 1
),我要定义具有返回true的自定义列。我该怎么做?
我要使用
$posts = $this->getRepository('Post')->findBy(array(
'user' => $user,
'isPublished' => true,
));
而不是
$this->getEM()->createQueryBuilder()
->select('p')
->from('BTBundle:Post', 'p')
->where('p.isModered = true')
->andWhere('p.pubDate < :date')
->andWhere('p.user = :user')
->setParameter(':date', new DateTime())
->setParameter(':user', $user)
->getQuery()->execute();
最简单的方法是创建一个计算的列。所以这样的东西。
CREATE TABLE dbo.Example
(
ExampleId int IDENTITY (1,1) NOT NULL,
Value1 INT
Value2 INT
ComputedCol AS Value1 + Value2
);
您可以在AS语句中使用任何有效的SQL逻辑。