Should i be not wrong then Rails features its own foreign key logic implemented using ActiveRecord. Is the fact that to assist performance i.e. to ensure that you do not depend around the database for that additional processing logic or make frequent database transactions? Or will it be for another reason?
No, that's to prevent duplication. DRY. The foreign key relationship within the database is reflected within the application. There must be only somewhere that relationship is referred to.
I'd think it had been concerning the robustness from the application.
A DBA can certainly remove any foriegn key constraint departing your application inside a mess.
An effort to place will raise an SQL exception. For those who have several foreign key constraints on the table it is a discomfort exercising which column and cost triggered the exception. It's much simpler to check on first and provide the consumer a menaingful^h^h^h^h^h^henacing^h^h^h^h^h^h^h^hmeaningful error message.
In large databases it is common practice to show off foriegn key constaints both to accelerate performance and also to make maintenance, backup/recovery, and replication less error prone.
Rails still uses foreign secrets just like normal. It is simply it does not enforce using foreign key constraints.
You are able to manage without needing explicit foreign key constraints within the database, presuming you place up validations inside your models to prevent data corruption.
It's a type of duplication to define constraints, however i prefer it for maintaining data integrity. Despite ActiveRecord associations and validations defined, will still be too simple to screw up the information structure throughout migrations, or bulk updates etc. You will find numerous plug ins making it simple to define your FKs DRYly in your normal ActiveRecord migrations
Also, even when you do not create FK constraints associations, you will still most likely wish to define a minimum of a catalog around the foreign key then when you need to do something similar to
post.comments you are not leading to a complete table scan to locate all of the comments using the matching
post_id (whenever you define FK constraints, lots of DBMSs do this unconditionally for you personally).