【问题标题】:CAKEphp Virtual field not workingCAKEphp虚拟字段不起作用
【发布时间】:2023-03-29 16:17:02
【问题描述】:

因为我的表中有两个价格列(subscription_discount 和 subscription_price)。我需要找到一种方法来找到两者中最低的一个并使用它。问题是只有在 subscription_discount 低于 subscription_price 且 subscription_discount 不为 0.00 时才会发生这种情况。

这是我在模型中创建虚拟字段的代码:

public $virtualFields = array(
    'end_price' => "IF(Abonnement.subscription_discount IS NOT NULL OR Abonnement.subscription_discount < Abonnement.subscription_price, Abonnement.subscription_price), Abonnement.subscription_discount)"
    );

在我看来,这最终会导致错误:

错误:SQLSTATE[42000]:语法错误或访问冲突:1064 你 您的 SQL 语法有错误;检查对应的手册 您的 MySQL 服务器版本,以便在 ') 附近使用正确的语法, Abonnement.subscription_discount)) AS Abonnement__end_price FROM 第 1 行的“蛋糕”

我不明白这里出了什么问题。

【问题讨论】:

    标签: php mysql cakephp


    【解决方案1】:
    public $virtualFields = array(
        'end_price' => "IF(Abonnement.subscription_discount IS NOT NULL OR Abonnement.subscription_discount < Abonnement.subscription_price, Abonnement.subscription_price>>>**)**<<<, Abonnement.subscription_discount)"
        );
    

    删除它

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多