avenirer / CodeIgniter-MY_Model

Base model (MY_Model) for the Codeigniter framework.
325 stars 204 forks source link

soft delete error #273

Closed swearl closed 6 years ago

swearl commented 6 years ago

CI 3.1.8 dbprefix is set to "my_"

$this->soft_deletes = true;

i use get function, error appear.

Error Number: 1054

Unknown column 'accounts.deleted_at' in 'where clause'

SELECT * FROM `my_accounts` WHERE `account` = 'admin' AND accounts.deleted_at IS NULL LIMIT 1

Filename: core/MY_Model.php

Line Number: 907

the table of deleted_at didn't add the dbprefix.

avenirer commented 6 years ago

Hello @swearl . Could you try to change the MY_Model.php line 1922 from:

            $this->table = $this->_get_table_name(get_class($this));

to

            $this->table = dbprefix($this->_get_table_name(get_class($this)));

and tell me if this solves the problem?

swearl commented 6 years ago

what is the dbprefix function?

avenirer commented 6 years ago

Isn't it a CodeIgniter function? https://codeigniter.com/user_guide/database/query_builder.html?highlight=dbprefix#CI_DB_query_builder::dbprefix

Did you try it?

swearl commented 6 years ago

i see, it means

$this->table = $this->_database->dbprefix($this->_get_table_name(get_class($this)));

thanks, seems work fine.

avenirer commented 6 years ago

Could you do a pull request for this?