Forum: Ruby foreign keys in Ruby on Rails

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
spambak (Guest)
on 2005-11-18 17:09
(Received via mailing list)
Should the foreign key constraints only be declared in the Model code of
the application, or in both the code and the database?
J. M. (Guest)
on 2005-11-18 17:46
spambak wrote:
> Should the foreign key constraints only be declared in the Model code of
> the application, or in both the code and the database?

Why not ask on the Rails list?

If your database can be used from other programs, you want the
constraints to exist in the database (so they can't be broken by other
software that ignores them).  Otherwise, it seems to me, it's just
overhead.

You could say that about any validation logic you write into your model
(or get for free from ActiveRecord) -- perhaps it should be duplicated
by validation triggers in your database, so that other code can't mess
it up -- but when you do that, you seem to lose a large amount of the
advantage of Rails over other web-database frameworks.

Good luck...
This topic is locked and can not be replied to.