Skip to content

Instantly share code, notes, and snippets.

@brantwedel
Last active December 25, 2015 19:49
Show Gist options
  • Save brantwedel/7030937 to your computer and use it in GitHub Desktop.
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
# 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