thinkphp5 开启软删除后,模型构造的SQL语句错误

浏览:433 发布日期:2018/03/29 分类:ThinkPHP5专区
查询

数据表字段

构造的SQL    SELECT * FROM ( SELECT * FROM tp5_system_history_1 UNION SELECT * FROM tp5_system_history_2 UNION SELECT * FROM tp5_system_history_3 UNION SELECT * FROM tp5_system_history_4 UNION SELECT * FROM tp5_system_history_5) AS SystemHistory WHERE `( SELECT * FROM tp5_system_history_1 UNION SELECT * FROM tp5_system_history_2 UNION SELECT * FROM tp5_system_history_3 UNION SELECT * FROM tp5_system_history_4 UNION SELECT * FROM tp5_system_history_5) AS SystemHistory`.`delete_time` IS NULL ORDER BY `sh_id` LIMIT 20这个问题不知道是BUG还是我什么地方做得不对,我感觉是软删除开启后,模型分表构造SQL的时候,直接把联合查询的语句拿过来了
正确的SQL应该是SELECT
    *
FROM
    (
        SELECT
            *
        FROM
            tp5_system_history_1
        UNION
            SELECT
                *
            FROM
                tp5_system_history_2
            UNION
                SELECT
                    *
                FROM
                    tp5_system_history_3
                UNION
                    SELECT
                        *
                    FROM
                        tp5_system_history_4
                    UNION
                        SELECT
                            *
                        FROM
                            tp5_system_history_5
    ) AS SystemHistory
WHERE
    `SystemHistory`.`delete_time` IS NULL
ORDER BY
    `sh_id`
LIMIT 20
最佳答案
评论( 相关
后面还有条评论,点击查看>>