diff --git a/library/think/db/builder/Mysql.php b/library/think/db/builder/Mysql.php index de38fac5..e432e396 100644 --- a/library/think/db/builder/Mysql.php +++ b/library/think/db/builder/Mysql.php @@ -38,6 +38,8 @@ class Mysql extends Builder list($table, $key) = explode('.', $key, 2); if (isset($options['alias'][$table])) { $table = $options['alias'][$table]; + } elseif ('__TABLE__' == $table) { + $table = $this->query->getTable(); } } if (!preg_match('/[,\'\"\*\(\)`.\s]/', $key)) { diff --git a/library/think/db/builder/Pgsql.php b/library/think/db/builder/Pgsql.php index 8b853a2f..67b98b44 100644 --- a/library/think/db/builder/Pgsql.php +++ b/library/think/db/builder/Pgsql.php @@ -57,6 +57,8 @@ class Pgsql extends Builder list($table, $key) = explode('.', $key, 2); if (isset($options['alias'][$table])) { $table = $options['alias'][$table]; + } elseif ('__TABLE__' == $table) { + $table = $this->query->getTable(); } } if (isset($table)) { diff --git a/library/think/db/builder/Sqlite.php b/library/think/db/builder/Sqlite.php index 02d1bf2e..680b4965 100644 --- a/library/think/db/builder/Sqlite.php +++ b/library/think/db/builder/Sqlite.php @@ -62,6 +62,8 @@ class Sqlite extends Builder list($table, $key) = explode('.', $key, 2); if (isset($options['alias'][$table])) { $table = $options['alias'][$table]; + } elseif ('__TABLE__' == $table) { + $table = $this->query->getTable(); } } if (isset($table)) { diff --git a/library/think/db/builder/Sqlsrv.php b/library/think/db/builder/Sqlsrv.php index d2f418f3..99f68409 100644 --- a/library/think/db/builder/Sqlsrv.php +++ b/library/think/db/builder/Sqlsrv.php @@ -75,6 +75,8 @@ class Sqlsrv extends Builder list($table, $key) = explode('.', $key, 2); if (isset($options['alias'][$table])) { $table = $options['alias'][$table]; + } elseif ('__TABLE__' == $table) { + $table = $this->query->getTable(); } } if (!is_numeric($key) && !preg_match('/[,\'\"\*\(\)\[.\s]/', $key)) { diff --git a/library/traits/model/SoftDelete.php b/library/traits/model/SoftDelete.php index 720b6e88..2b97ff72 100644 --- a/library/traits/model/SoftDelete.php +++ b/library/traits/model/SoftDelete.php @@ -142,7 +142,7 @@ trait SoftDelete { $field = isset($this->deleteTime) ? $this->deleteTime : 'delete_time'; if (!strpos($field, '.')) { - $field = $this->db(false)->getTable() . '.' . $field; + $field = '__TABLE__.' . $field; } if (!$read && strpos($field, '.')) { $array = explode('.', $field);