Symfony2 Doctrine CAST AS DECIMAL(Symfony2 Doctrine CAST AS DECIMAL)
问题描述
我在 Symfony2 中使用 Sonata Admin Bundle 并有一个自定义过滤器.在数据库中,列是浮动的(无法更改).如果你输入 1333.33 将没有结果.
I use Sonata Admin Bundle in Symfony2 and have a custom filter. In database, column is float (cannot change it). If you type 1333.33 there will be no result.
一种解决方案是使用 CAST:
One solution is to use CAST:
CAST( o.price AS DECIMAL) = CAST( 399.99 AS DECIMAL)
查询在 SQL 中运行良好,但 Doctrine 抛出错误.所以我的问题是如何在 Doctrine 或其他可靠的解决方案中使用 CAST?
Query is working just fine in SQL but Doctrine throws an error. So my question is how can use CAST in Doctrine or another reliable solution?
推荐答案
Doctrine 在其 DQL 中没有提供 CAST
构造(参见 这个列表).
Doctrine does not provide a CAST
construct in its DQL (see this list).
但对于您的特殊情况,比较乘以 100 的值应该足够了:
But for your special case, it should be enough to compare the values multiplyed by 100:
o.price * 100 = 399.99 * 100
这篇关于Symfony2 Doctrine CAST AS DECIMAL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Symfony2 Doctrine CAST AS DECIMAL


基础教程推荐
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何替换eregi() 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01