Any support for foreign keys in CakePHP's schema wrapper or migrations?

I'm new to CakePHP and I'm trying to decide between the schema wrapper that comes with CakePHP and the migration tools that were written by Joel Moss and Georgy Momchilov .

So far, I have not found direct support in any of them for creating foreign key constraints. It looks like you could write raw SQL in migration to create a foreign key.

Did I miss something? Is there support somewhere? Should I be using foreign keys? I've seen several comments related to CakePHP or Ruby on Rails that say foreign key constraints are discouraged. Our database is only used by one application.

+2


source to share


1 answer


I would not say that they are discouraged as such. With CakePHP and Rails, the data integrity provided by foreign keys is handled by the framework. However, this is only true if you do it "right". If you are writing your own SQL, working in a non-standard way, or accessing the data through any other means, then good keys are definitely a good idea in my opinion.



I've never used the migration tools for CakePHP, but in my limited Rails work I've always applied keys in migrations using SQL. This way you get all the inherent benefits. You have a migration and you get your domain restrictions in case you ever bypass the framework to achieve a certain result.

+2


source







All Articles