Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

DB BaseBuilder Join() - RawSql as table

未關閉
#9,070 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

@wakqasahmed 已經在處理了。

開始於 2026年9月19日。

  • #10571 來自 @wakqasahmed —— 未關閉

評估

難度
3/5
預估耗時
1-2 天
新手友好度
42/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
停滯
技術堆疊
php
領域
database

研究方向

從 system/Database/BaseBuilder.php 中的 join() 和 trackAliases() 開始,然後檢查 system/Model.php 第 930 行的呼叫。驗證可以將 RawSql 資料表傳遞給 join() 而不會產生 TypeError,同時現有的字串和帶有別名資料表的 join 仍能正常運作。

由索引模型根據 Issue 內容生成。

描述

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.

主要語言
PHP
星號
6k
分支
2k
平均合併
1 天 22 小時
30 天內合併 PR
59

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

codeigniter4/CodeIgniter4 的其他 Issue

查看 codeigniter4/CodeIgniter4 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。