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

I'm having what looks to me like a bug.
I have a model configured like this:

PHP Code:
protected $table         'sottoeventi';
protected 
$primaryKey    'id';

protected 
$returnType    'object';

protected 
$allowedFields = [
    'id_pdv',
    'id_evento',
    'focus',
    'status',
    'ultima_modifica',
    'sostituisce',
    'invio_sms',
    'ab_est',
    'motivazione',
];

protected 
$validationRules    = [
    'id_pdv' => 'required|is_natural_no_zero',
];

protected 
$validationMessages = [
    'id_pdv' => [
        'required'          => 'App.campo_vuoto',
        'is_natural_no_zero' => 'App.campo_vuoto',
    ],
]; 



Here are a number of methods that use CRUDs to execute various queries on the table set in $table.

but in certain situations I need to run queries on other tables before or after, so, in the specific case I have this kind of situation:


PHP Code:
// More code

else :

    // I delete a certain recored from a different table than the one set in $table and then I use the function table('my_different_table')
    $this->db->table('sottoeventi_personale')->where('id_sottoevento', (int)$id_sottoevento)->delete();

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

    // Update the record on the main table set to $table
    $this->where('id', (int)$id_sottoevento)
        ->update(
            [
                'data_inizio' => '0000-00-00',
                'data_fine'  => '0000-00-00'
            ]
        );

endif; 


By doing so, however, I receive an error from the second query, that of update on the model table ($table)

There is no data to update.

If I modify the query using the table() function like this:

PHP Code:
$this->db->table('sottoeventi')->where('id', (int)$id_sottoevento)
    ->update(
        [
            'data_inizio' => '0000-00-00',
            'data_fine'  => '0000-00-00'
        ]
    ); 

everything works

I tried printing the $this->table variable, before and after the first query, but the value is correct.

At this point, I would expect the query to work normally when I update like this:

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

Didn't I understand? or is there something wrong?
Reply


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



Theme © iAndrew 2016 - Forum software by © MyBB