Skip to content

Commit d4115dd

Browse files
authored
Merge pull request #5378 from kenjis/fix-4457-BaseBuilder-tableName
fix: Incorrect type `BaseBuilder::$tableName`
2 parents 775f50c + 8c638e0 commit d4115dd

3 files changed

Lines changed: 15 additions & 3 deletions

File tree

system/Database/BaseBuilder.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ class BaseBuilder
158158
* Tracked separately because $QBFrom gets escaped
159159
* and prefixed.
160160
*
161+
* When $tableName to the constructor has multiple tables,
162+
* the value is empty string.
163+
*
161164
* @var string
162165
*/
163166
protected $tableName;
@@ -261,7 +264,9 @@ class BaseBuilder
261264
/**
262265
* Constructor
263266
*
264-
* @param array|string $tableName
267+
* @param array|string $tableName tablename or tablenames with or without aliases
268+
*
269+
* Examples of $tableName: `mytable`, `jobs j`, `jobs j, users u`, `['jobs j','users u']`
265270
*
266271
* @throws DatabaseException
267272
*/
@@ -276,7 +281,13 @@ public function __construct($tableName, ConnectionInterface &$db, ?array $option
276281
*/
277282
$this->db = $db;
278283

279-
$this->tableName = $tableName;
284+
// If it contains `,`, it has multiple tables
285+
if (is_string($tableName) && strpos($tableName, ',') === false) {
286+
$this->tableName = $tableName; // @TODO remove alias if exists
287+
} else {
288+
$this->tableName = '';
289+
}
290+
280291
$this->from($tableName);
281292

282293
if (! empty($options)) {

system/Database/BaseConnection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ abstract protected function _transCommit(): bool;
835835
abstract protected function _transRollback(): bool;
836836

837837
/**
838-
* Returns an instance of the query builder for this connection.
838+
* Returns a non-shared new instance of the query builder for this connection.
839839
*
840840
* @param array|string $tableName
841841
*

user_guide_src/source/changelogs/v4.1.6.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Release Date: Not released
1111

1212
BREAKING
1313
========
14+
- Multiple table names will no longer be stored in ``BaseBuilder::$tableName`` - an empty string will be used instead.
1415

1516
Enhancements
1617
============

0 commit comments

Comments
 (0)