Welcome Guest, Not a member yet? Register   Sign In
Model basic CRUD methods and other queries on other tables using $this->db->table()
#10

(This post was last modified: 02-22-2023, 03:28 AM by serialkiller.)

(02-22-2023, 03:06 AM)kenjis Wrote: When you use  table('table_name'), you are using a new Query Builder instance directly.
You are not using the Model.

Yes, I know this, this is the problem right here, because if I don't use table() of the query builder, the query fails?

The Model has its own table set, and the query in question should use that table "sottoeventi".

Code:
protected $table = 'sottoeventi';

In the specific case I first run other queries with the query builder, use different tables than the model one, then use table('other_table').



PHP Code:
$this->db->table('sottoeventi_personale')->where('id_sottoevento', (int)$id_sottoevento)->delete();

// Log
$basic_stuff_model->save_log('Delete giornate sottoevento'$this->db->getLastQuery());

$this->where('id', (int)$id_sottoevento)
        ->update(
            [
                'data_inizio' => '0000-00-00',
                'data_fine'   => '0000-00-00'
            ]
        ); 

The update query returns the error "There is no data to update", while you expect it to update the "sottoeventi" table, which is the Model
Reply


Messages In This Thread
RE: Model basic CRUD methods and other queries on other tables using $this->db->table() - by serialkiller - 02-22-2023, 03:27 AM



Theme © iAndrew 2016 - Forum software by © MyBB