• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
delete don't work

#1
[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.

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

Maybe contain more error info or other things.

#3
[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?)

#4
[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.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.