pardon my brace } typo on the last message

On May 20, 8:27 pm, JamesF <usaexportexpe...@gmail.com> wrote:
> you could execute a delete call from the controller.
>
> i assume your delete action is in the posts controller and it hasMany
> ('Comments');
>
> function delete ($id = null)
> {
>
> //contain the post model (always good practice to limit extra db
> calls .. or use recursive attribute in conditions
> $this->Post->Behaviors->attach('Containable');
> $this->Post->contain();
>
> //if we find a Post with the passed ID (please also include logic to
> authorize this action)
> if ($this->Post->find('first', array('conditions'=>array('Post.id'=>
> $id))))
> {
> //delete post with passed id
> $this->Post->delete($id);
>
> //delete all comments with fk post_id that equals $id
> $this->Post->Comment->deleteAll(array(‘Comment.post_id’ => $id));
>
> }
>
> hope this helps
>
> }
>
> On May 20, 6:45 pm, Jorge Garifuna <garif...@gmail.com> wrote:
>
> > Thank you for the update.
>
> > Is there a way that cakePHP can handle this internally?
>
> > On Wed, May 20, 2009 at 2:18 PM, harrzack <a...@sargasso-sea.net> wrote:
>
> > > If you use the InnoDB engine, you can set up proper relationships. You
> > > have a Foreign key in the child tables that ties it to the Parent
> > > table. There are Constraints set to the  built into the InnoDB that
> > > you set for ON DELETE and ON UPDATE, and when the Parent is deleted,
> > > there is a cascade to delete all children.
>
> > >  Read here:
> > >http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints...
>
> > > On May 20, 2:48 pm, Jorge Garifuna <garif...@gmail.com> wrote:
> > > > I just deleted a post with comments and the comments related to that
> > > > post were not deleted (left as orphan records).
>
> > > > Is there a way to delete related records when the master gets deleted,
> > > > so they wont be left as orphan records?
>
> > > > Thanks,
>
> > > > Jorge
>
> > --
> > Jorge Garifuna
> > Professional Web Developer
> > "Your Web Solution Partner"
> > Garinet Media Network, LLC.
> > 811 Wilshire Blvd. Suite 1705
> > Los Angeles, CA 90017http://www.GariDigital.com
> > Business Operating Hours: Monday - Friday: 9AM - 6 PM PST
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to