Welcome Guest, Not a member yet? Register   Sign In
Active Record Delete Weirdness
#1

[eluser]Lowkase[/eluser]
Well,

I am stumped on this one, here is calling code:

// Start MySQL Transaction
$this->db->trans_start();

// Delete the color from the color table
$this->colors_model->delete($color_id);

// OTHER CALLS TO MODELS

// Complete the MySQL Transaction
$this->db->trans_complete();


Here is the delete function in the colors_model:

// DELETE
function delete($id)
{
$this->db->delete( 'colors', array('id' => $id) );
}


Active record deletes the specific ID I am passing to the function, however, somehow, ActiveRecord is deleting the FIRST record from the same table as well.

There is one other place in the code that I call the delete function in the colors_model but it does not produce the same "buggy" result.

Anyone ever run into this situation?


Thanks,

Lokase
#2

[eluser]WanWizard[/eluser]
In general, nothing gets deleted without a proper WHERE clause. There is nothing distinctive about a 'first' row in a table, other than that it might be a record with the lowest ID in case auto_increment is used.

Activate the profiler, to see which queries are exactly executed.

Alternatively, you can dump the queries using
Code:
var_dump( $this->db->queries );
#3

[eluser]Lowkase[/eluser]
So,

I took another angle at the same problem. Instead of passing the ID I am passing the IMAGE NAME and try to delete the record using the following code in the color model:

function delete_by_image($image)
{
$this->db->delete( 'colors', array('image' => $image) );
}

This function produces the desired result, only the specified record is deleted and the first record is not deleted.

Have I screwed up the CREATE for the color table?

CREATE TABLE `colors` (
`id` int(11) NOT NULL auto_increment,
`description` text NOT NULL,
`image` text NOT NULL,
`color_code` tinytext,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=48 DEFAULT CHARSET=latin1;


I can keep moving forward, but the delete by id issue is grating at me.

Thanks for any thoughts.


Lowkase
#4

[eluser]Lowkase[/eluser]
Thanks for the debugging suggestions Wan, I will give those a try.

Lowkase
#5

[eluser]WanWizard[/eluser]
Don't see anything wrong with that table. Still can't understand why records would be 'magically' deleted...




Theme © iAndrew 2016 - Forum software by © MyBB