Skip to content

Instantly share code, notes, and snippets.

@shamil614
Created April 5, 2012 19:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shamil614/2313328 to your computer and use it in GitHub Desktop.
Save shamil614/2313328 to your computer and use it in GitHub Desktop.
Load all Models and iterate to see if user_id column exists
# Applies to Rails 2.3
# Since Rails doesn't load classes unless it needs them, you must read the models from the folder. Here is the code
Dir[Rails.root.to_s + '/app/models/**/*.rb'].each do |file|
begin
require file
rescue
end
end
Object.subclasses_of(ActiveRecord::Base).each do |model|
if model.columns.map(&:name).include?("user_id")
puts "#{model.name} has User Assoc"
model.all.each do |obj|
delete_obj(obj)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment