沃梦达 / 编程问答 / php问题 / 正文

Symfony2 Doctrine CAST AS DECIMAL

Symfony2 Doctrine CAST AS DECIMAL(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

基础教程推荐