Active Record Delete Weirdness - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Active Record Delete Weirdness (/showthread.php?tid=31727) |
Active Record Delete Weirdness - El Forum - 06-29-2010 [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 Active Record Delete Weirdness - El Forum - 06-29-2010 [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 ); Active Record Delete Weirdness - El Forum - 06-29-2010 [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 Active Record Delete Weirdness - El Forum - 06-29-2010 [eluser]Lowkase[/eluser] Thanks for the debugging suggestions Wan, I will give those a try. Lowkase Active Record Delete Weirdness - El Forum - 06-29-2010 [eluser]WanWizard[/eluser] Don't see anything wrong with that table. Still can't understand why records would be 'magically' deleted... |