Doctrine中的反向布尔值 [英] Reverse Boolean value in Doctrine
问题描述
我正在使用Symfony2和Doctrine查询生成器。有没有一个简单的方法来反转数据库中的布尔值?
我已经尝试过没有运气:
$ query-> update('AppMonitorBundle:Monitor','m')
- > set('m.isActive','!m.isActive')
- > where('m.id =:monitor')
- > setParameter('monitor',$ monitor)
- > getQuery()
- > ; execute()
;
我认为在SQL中可以工作,但它给了我:
[Syntax Error] line 0,col 51:Error:Expected Literal,got'!'
替换!
这是一个解决方法:
- > set('m.isActive','1-m.isActive')
测试并为我工作。
布尔值只是一个0(作为假)和1(如真实)。因此,如果 m.isActive
为true,则反向值将 false(1-1 = 0 = false)
。如果 m.isActive
为false,则反面将 true(1-0 = 1 = true)
。 / p>
I'm using Symfony2 and the Doctrine query builder. Is there an easy way to reverse a Boolean in the database?
I've tried this with no luck:
$query->update('AppMonitorBundle:Monitor', 'm')
->set('m.isActive', '!m.isActive')
->where('m.id = :monitor')
->setParameter('monitor', $monitor)
->getQuery()
->execute()
;
Which I believe would work in SQL but it gives me:
[Syntax Error] line 0, col 51: Error: Expected Literal, got '!'
Substituting ! for NOT gives the same result.
Here is a workaround:
->set('m.isActive', '1-m.isActive')
Tested and worked for me.
A boolean is just a 0 (as false) and 1 (as true). So if m.isActive
is true, then the reverse value will false (1-1 = 0 = false)
. And if m.isActive
is false, the reverse side will true (1-0 = 1 = true)
.
这篇关于Doctrine中的反向布尔值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!