Foreign keys, indexes and referential integrity are important for the database 
for reasons way beyond the PHP/Ajax you have written to interact with it, such 
as performance and data integrity. I would never abandon them.

My 2c worth: If cascading deletes (CD) are [really] important to the model I am 
working on, I would build them into the database. That's its natural 
environment, so it's where it belongs; let the db do what it was born to do. If 
the db couldn't handle CD, I'd see if changing the engine was feasible. If not, 
I'd rely on my code. Some other considerations; if anything else (some other 
API for example) is going to interact with the db, then it makes sense to build 
the logic once into the db rather than twice in separate code. If it is ever 
likely that the db engine could change in the future and I can't guarantee that 
the new db engine can handle CD, I'd build it into the code. What if the code 
base is rewritten from PHP to some other language? Then again it makes sense to 
have already taken care of CD in the db.

For the mechanism, I'd start with triggers on delete and on update that fire 
stored procedures. I know triggers can be untrendy, but they work at the point 
you need to fire them (and I sleep at night). And I'd always wrap things in 
transactions (and I sleep even better).

I guess there is no definitive answer though.

Jeremy Burns
Class Outfit

jeremybu...@classoutfit.com
http://www.classoutfit.com

On 16 Mar 2011, at 04:32, Zaky Katalan-Ezra wrote:

> I try to follow these rules of thumb 
> 1. If the database know how to do it do it in the database.
> 2. The less code you write the better.
> 
> Writing functional processes in the database give you more option to test 
> your logic.
> If it work in the database and not in the application you know where you need 
> to put all your efforts.
> 
> Although I must admit I stopped setting foreign keys since cake understand 
> the reference automatically throw convention.
> 
> More important question is whether to use stored procedure instead of using 
> application code?
> In this case also I prefer using the database features, in many cases it save 
> some transactions.   
> 
> -- 
> Our newest site for the community: CakePHP Video Tutorials 
> http://tv.cakephp.org 
> Check out the new CakePHP Questions site http://ask.cakephp.org and help 
> others with their CakePHP related questions.
>  
>  
> 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

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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

Reply via email to