2008年10月17日星期五

Re: [fw-db] Re: Re[fw-db] ferencemap: delete CASCADE

On Oct 17, 2008, at 9:15 AM, EducatedFool wrote:

> Another question. Is there something in the zend framework where:
> when I
> want to delete something it checks if the value is used in another
> table,
> and don't delete it when it is.
>
> e.g. table with articles. Every articles is connected with a
> category. when
> I try to delete a category, it 'll check if that id is used in the
> table
> articles. If used, it 'll not delete it. If not used, the category
> can be
> deleted.

This is best handled by a foreign key constraint with the ON DELETE
RESTRICT modifier. You must use a storage engine that supports
foreign key constraints. MyISAM cannot do this, but InnoDB can.
There's no way to do this atomically in client-side code.

Regards,
Bill Karwin

没有评论: