Last active
December 25, 2015 19:49
-
-
Save brantwedel/7030937 to your computer and use it in GitHub Desktop.
Sequential ID's for ActiveRecord Fixtures. For using fixtures in db/seeds.rb
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
# Open and override ActiveRecord::FixtureSet with new identify method implementation to support sequentual ID's | |
module ActiveRecord | |
class FixtureSet | |
@@seq_id = 0 | |
@@seq_keys = {} | |
def self.identify(label) | |
@@seq_keys[label] ||= begin | |
@@seq_id += 1 | |
@@seq_id | |
end | |
@@seq_keys[label] | |
end | |
end | |
end | |
#ActiveRecord::Fixtures.create_fixtures("#{Rails.root}/test/fixtures", ["users"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment