Created
April 5, 2012 19:12
-
-
Save shamil614/2313328 to your computer and use it in GitHub Desktop.
Load all Models and iterate to see if user_id column exists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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