Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

DB BaseBuilder Join() - RawSql as table

Offen
#9,070 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@wakqasahmed arbeitet bereits daran.

Seit 19.9.2026.

  • #10571 von @wakqasahmed — offen

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
42/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Veraltet
Tech-Stack
php
Bereich
database

Rechercherichtung

Beginne in system/Database/BaseBuilder.php bei join() und trackAliases() und untersuche anschließend den Aufruf aus system/Model.php in Zeile 930. Überprüfe, dass eine RawSql-Tabelle an join() übergeben werden kann, ohne einen TypeError zu verursachen, und dass bestehende Joins mit Strings und Aliased Tables weiterhin funktionieren.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

database enhancement
PHP Version

8.2

CodeIgniter4 Version

4.5.3

CodeIgniter4 Installation Method

Composer (using codeigniter4/appstarter)

Which operating systems have you tested for this bug?

Windows

Which server did you use?

apache

Database

No response

What happened?

CRITICAL - 2024-07-24 14:10:15 --> TypeError: CodeIgniter\Database\BaseBuilder::join(): Argument #1 ($table) must be of type string, CodeIgniter\Database\RawSql given, called in C:\xampp\portal\vendor\codeigniter4\framework\system\Model.php on line 930
[Method: GET, Route: public/fuel/pricing/getprice]
in SYSTEMPATH\Database\BaseBuilder.php on line 620.
1 SYSTEMPATH\Model.php(930): CodeIgniter\Database\BaseBuilder->join(Object(CodeIgniter\Database\RawSql), 't5.product_id = fpp.id', 'inner')

Steps to Reproduce

Used to be able to use RawSql for table on join()

        $builder = $this
            ->select("{$this->table}.description_id AS id, fpd.description,
                    fpp.product,
                    DATE({$this->table}.effective) AS effective,
                    {$priceField}")
            ->join(
                "{$this->descTable} AS fpd",
                "fpd.id = {$this->table}.description_id",
                'inner'
            )
            ->join(
                "{$this->prodTable} AS fpp",
                "fpp.id = {$this->table}.product_id",
                'inner'
            );

        $sql = "(SELECT
		fpp.id AS product_id,
		IF(ph.TAXCLASS IS NULL,0,ph.TAXCLASS) AS taxclass,
		IF(pw.SALESTAXCLASS IS NULL,0,pw.SALESTAXCLASS) AS salestaxclass
		FROM
		misc.fuel_prices_product AS fpp
		LEFT JOIN pds.pds_prodhead AS ph ON ph.PRODUCTCODE = fpp.product
		LEFT JOIN pds.pds_prodware AS pw ON pw.PRODUCTCODE = fpp.product AND pw.PACKCODE = '' AND pw.WHALPHA = 3
		GROUP BY fpp.id) t5";

        $builder->join(
            new RawSql($sql),
            "t5.product_id = `fpp`.id",
            'inner'
        );

        // $params['id'] = 14;
        $builder->where("{$this->table}.description_id", $params['id']);

        $builder->where("DATE({$this->table}.effective) BETWEEN DATE_SUB('{$params['fromdate']}',INTERVAL 15 DAY) AND '{$params['todate']}'");

        $builder->where('fpp.product', $params['product']);

        $builder->groupBY("DATE({$this->table}.effective)");

        $builder->orderBy("{$this->table}.effective", 'ASC');

        $data = $builder->get()->getResultObject();
Expected Output

Get errors now.

Fix by adding adding RawSq type:

    public function join(string|RawSql $table, $cond, string $type = '', ?bool $escape = null)
    {

Adding is_string($table) twice in BaseBuilder::trackAliases()

    protected function trackAliases($table)
    {
        if (is_array($table)) {
            foreach ($table as $t) {
                $this->trackAliases($t);
            }

            return;
        }

        // Does the string contain a comma?  If so, we need to separate
        // the string into discreet statements
        if (is_string($table) && str_contains($table, ',')) {
            return $this->trackAliases(explode(',', $table));
        }

        // if a table alias is used we can recognize it by a space
        if (is_string($table) && str_contains($table, ' ')) {
Anything else?

I'd send in a PR but I'm slammed busy at the moment and I don't have my development environment ready.

Vorherrschende Sprache
PHP
Sterne
6k
Forks
2k
Ø Merge
1 T. 22 Std.
Gemergte PRs (30 T.)
59

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus codeigniter4/CodeIgniter4

Alle Issues in codeigniter4/CodeIgniter4

Ähnliche Issues

Weitere Issues zu PHP

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.