Thanks, that's what I was looking for, I have not used behaviors yet.
While researching beforeDelete I came across the hasAny() function
which also helps.

My current way of doing things also displays a list of all the records
("books") that belongTo the record that has been attempted to be
deleted ("author"), so the jury's still out on if coding this with a
behavior would simplify things. I'll have to experiment a bit more.

On Apr 14, 11:26 am, Richard <rclay...@gmail.com> wrote:
> Depending on your database, you may be able to use constraints on the
> foreign keys of your database ("ON DELETE RESTRICT"), however that's a
> responsive check rather than pro-active. In your situation, you may find
> creating a behavior would be beneficial. The behavior would run the checks
> on the beforeDelete callback and you can restrict it at that level instead
> of a database.
>
> Richard
>
> On Tue, Apr 14, 2009 at 3:41 PM, qwanta <rgmic...@gmail.com> wrote:
>
> > In the case where If I have a one to many relationship like Authors-
> > >Books and I would like to delete an author - but only if this author
> > has no books - is there a buiilt-in way to check?
>
> > I find that I run into this situation a lot (every time a table has a
> > foreign key), and at the moment manually write a function in the model
> > to check this. eg. for the Books model a method with the author_id as
> > parameter that returns true if the author has books, false otherwise.
> > But it seems like cakephp should be able to check this based on the
> > model relationships, so is there something built-in I am missing?
>
> > Thanks
--~--~---------~--~----~------------~-------~--~----~
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