In a Rails application, I have external key restrictions in MySQL that I set them manually, separately from my migrations.
I am trying to figure out whether to use the ActiveRecord :dependent => :destroy parameter. For example, in my schema, I have tables ...
users ----- log_entries ----------- user_id
And in my model, I could ...
class User < ActiveRecord::Base has_many :log_entries, :dependent => :destroy end
Should I leave the dependent option on the model and just leave it in the database? Or is it good to have it there? When deleting things in this application, I do not need to run callbacks. In all cases, simply removing them is enough.
Another factor to consider is that the FK restrictions will not be present in my test environment, probably because rake db:test:prepare does not set them. So it's hard to check what happens if I rely completely on MySQL for cascading deletions.
ruby mysql ruby-on-rails activerecord
Ethan
source share