In a Rails app, I have foreign key constraints in MySQL which I set them all up manually, separate from my migrations.
I'm trying to figure out whether I should use ActiveRecord's :dependent => :destroy
option. For example, in my schema I have tables...
users
-----
log_entries
-----------
user_id # Has FK constraint to users.id with ON DELETE CASCADE
And in my model I could have...
class User < ActiveRecord::Base
has_many :log_entries, :dependent => :destroy
end
Should I leave out the dependent option on the model and just leave it up to the DB? Or is it good to have that in there? I don't need to run any callbacks when deleting things in this application. In all cases it's OK to simply delete them.
Another factor to consider is that the FK constraints won't be present in my test environment probably because rake db:test:prepare
doesn't set them up. So it's hard to test what happens if I'm relying totally on MySQL to cascade deletions.