Welcome Guest, Not a member yet? Register   Sign In
db->delete() is failing for some reason...
#1

[eluser]mikegioia[/eluser]
Hi guys -

I'm having a strange problem with active record deleting. Heres the following code I'm running:

Code:
$tables = array('table_1', 'table_2', 'table_3');
$this->db->where('user_id', $user_id);
if (! $this->db->delete($tables))
     return FALSE;

The db->delete() fails and is returning false for some reason. It successfully executed the delete on the first two tables, and the last query it executes is the DELETE on the final table in the array, but it's failing on that last one and return false.

I've tried just executing the DELETE on the final table and it works fine. Does anyone know if there are issues with doing DELETES on multiple tables like this?

Mike
#2

[eluser]barbazul[/eluser]
I've done some testing and checked the AR code and then I realized that for some reason, when multiple tables are passed in an array, the method simply returns NULL.
check DB_active_rec.php line 1318

so you'll always enter the if in your example.

Maybe there is the need to double check what the desired functionality for this AR method is, but to quickly fix your code use the following:

Code:
$success = TRUE;
foreach ($tables as $t) {
    if (! $this->db->delete($t,array("user_id"=>$user_id))) {
        $success = FALSE;
    }
}
return $success;
#3

[eluser]mikegioia[/eluser]
Thanks barbazul - thats exactly what I ended up doing. I might spend some time in the AR class to see if I can fix that for later.
#4

[eluser]barbazul[/eluser]
I think I'll open a thread in the bugs forum about this subject.




Theme © iAndrew 2016 - Forum software by © MyBB