CodeIgniter Forums
delete don't work - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: delete don't work (/showthread.php?tid=16494)



delete don't work - El Forum - 03-08-2009

[eluser]molistok[/eluser]
Hi,
I am trying to delete one register but I can't get it. This is my code:
Code:
class my_class extends IgnitedRecord {
...
   public function delete($id)
    {
        $this->where('id',$id);
        $rec=$this->find_all();
        foreach( $rec as $message)
        {
             $message->delete();
        }
    }
}

I check that $message is one row. I try this and after some seconds I get this message in Internet Explorer: "Internet Explorer cannot display the webpage".

Can any help me please?
Thanks.


delete don't work - El Forum - 03-11-2009

[eluser]Vi.[/eluser]
Did you tried this in Opera or Firefox?

Maybe contain more error info or other things.


delete don't work - El Forum - 03-16-2009

[eluser]m4rw3r[/eluser]
You end up in an infinite loop: controller -> my_class::delete() -> $message::delete() -> my_class::delete() -> $message::delete() -> ...
This because $message is tied to the my_class model, and according to the Data Mapper pattern is the model responsible for the deletion of the child objects ($message in this case), and you've overwritten the delete method (which $message::delete() calls).

To avoid this, why not just use $this->my_class->find($id)->delete(); ? (Or even AR, when it is so simple?)


delete don't work - El Forum - 03-22-2009

[eluser]molistok[/eluser]
Thanks for the replyes. Yes I did a infinit bucle because in my function exist a delete method. I am sorry. Thanks. Now works fine.