CodeIgniter Forums
Active Record Cache doesn't work with delete - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Active Record Cache doesn't work with delete (/showthread.php?tid=10639)



Active Record Cache doesn't work with delete - El Forum - 08-07-2008

[eluser]JeffChan[/eluser]
Active Record Cache

For whatever reason, it doesn't work with "delete"

For example:
Code:
<?php
$this->db->start_cache();
$this->db->where('project_id', $this->uri->segment(3));
$this->db->stop_cache();

$this->db->delete('projects');
$this->db->delete('comments');
$this->db->delete('media');
?>

The above code spits out an error stating that a "where" clause must be set for delete actions.


Active Record Cache doesn't work with delete - El Forum - 08-07-2008

[eluser]Derek Allard[/eluser]
Darn, that'd be my fault Jeff. I haven't looked into it, but could I ask you to make a post in the bug tracker with a link to this thread, and your example code? Thanks. Oh, and sorry your first post to the forum has to be a bug report - welcome aboard.


Active Record Cache doesn't work with delete - El Forum - 08-07-2008

[eluser]JeffChan[/eluser]
I've just submitted it: http://codeigniter.com/bug_tracker/bug/4998/

Thanks a lot for the reply. I'm always glad to help. Smile I've been only using CI for a few days and it's been fantastic Smile Good work on it!


Active Record Cache doesn't work with delete - El Forum - 08-08-2008

[eluser]Pascal Kriete[/eluser]
Active Record clears after every query it runs, so the where clause is gone when the second delete query runs.
Code:
$tables = array('projects', 'comments', 'media');
$this->db->where('id', $this->uri->segment(3));
$this->db->delete($tables);


Also, in my mind delete counts as a 'write-type' query..::confused::
Quote:Only read-type (SELECT) queries can be cached,



Active Record Cache doesn't work with delete - El Forum - 08-08-2008

[eluser]xwero[/eluser]
[quote author="inparo" date="1218221464"]
Also, in my mind delete counts as a 'write-type' query..::confused::
Quote:Only read-type (SELECT) queries can be cached,
[/quote]

This is because the insert, update and delete queries are passed on to the driver for compilation, only the select query is compiled in the AR class. If they change that it's possible to cache building methods for all the query types.


Active Record Cache doesn't work with delete - El Forum - 08-08-2008

[eluser]JeffChan[/eluser]
[quote author="inparo" date="1218221464"]Active Record clears after every query it runs, so the where clause is gone when the second delete query runs.
Code:
$tables = array('projects', 'comments', 'media');
$this->db->where('id', $this->uri->segment(3));
$this->db->delete($tables);


Also, in my mind delete counts as a 'write-type' query..::confused::
Quote:Only read-type (SELECT) queries can be cached,
[/quote]

Yeah that's correct, but keep in mind here that we're caching the "where" query not the "delete" query.

So theoretically, the where clause should have been cached when using $this->db->start_cache()/$this->db->stop_cache() and applied to subsequent queries until a flush.

Edit: Oops sorry. I think we're not on the same page... I was refering to the Active Record Cache not the database query cache.


Active Record Cache doesn't work with delete - El Forum - 08-08-2008

[eluser]Pascal Kriete[/eluser]
Ah, my mistake. It should indeed work for the AR cache.