codeigniter-model icon indicating copy to clipboard operation
codeigniter-model copied to clipboard

findOne with dbprefix

Open legionir opened this issue 1 year ago • 1 comments

Hello,

seems there is a bug with codeigniter "dbprefix" while using findOne and other WHERE methods. for example: $this->Products_model->findOne($id)

cause the following error:

Unknown column 'pl_`products.id' in 'where clause'

SELECT * FROM pl_products WHERE pl_``products.id = '1' LIMIT 1

I made a quick fix this change:

protected function _field($columnName)
{
    if ($this->alias)
    {
        return "`{$this->alias}`.`{$columnName}`";
    }

    if (!$this->_db->dbprefix)
    {
        return "`{$this->table}`.`{$columnName}`";
    }

    return "{$this->table}`.`{$columnName}`";
}

legionir avatar Aug 29 '23 08:08 legionir

Hi @legionir ,

You could try the version 2.19.3 to see whether the problem is solved smoothly with dbprefix setting.

Thank you for your support!

yidas avatar Aug 29 '23 11:08 yidas