php - 如何在 cakephp 3.X 的选择查询中键入强制转换数据库字段?
问题描述
在我的表中,我有一个十进制的数量字段。数据库中“数量”的值为 1.00,但是当我从查询中选择它时,它给了我整数 1。但是,如果该值为 1.25,它给出相同的浮点值 1.25。这是我的查询和输出 -
询问
$app_cart = $this->AppCart->find()->select(['AppCart.id','item'=>'Items.name','price'=>'Items.sales_rate','quantity'=>'AppCart.quantity'])
->where(['AppCart.user_id'=>1])->contain(['Items']);
输出
{
"success": true,
"message": "List Found",
"app_cart": [
{
"id": 4,
"item": "KANGAN SAREE",
"price": 1375,
"quantity": 1
},
{
"id": 5,
"item": "KANGAN SAREE",
"price": 1375,
"quantity": 1
}
]}
我努力了
$app_cart
->selectTypeMap()
->addDefaults([
'quantity' => 'decimal'
]);
解决方案
推荐阅读
- javascript - Javascript循环:返回1到10,然后再次(重新启动循环)
- c++ - 将一个函数名称传递给模板以在模板主体内使用它的多个重载
- javascript - 如何在本机反应中使用香草类?
- c# - StackExchange.Redis | TTL -2 | 问题
- azure - Azure 逻辑应用 - Azure 文本分析器错误 502 网关错误
- flutter - 使用 listview 关闭数据库数据
- c# - 加入时的慢速 LINQ 查询
- c# - EF Core Oracle Timestamp with Timezone to DateTime in c#
- java - sparkSession.getOrCreate() 出现错误
- scala - 如何添加参数以在 Ammonite 中运行 SBT?