As described in this article, I am using automatic associations in fixtures. For example, if a region object has a country id, instead of doing "country_id": 1, I do "country": "USA". "USA" is a label in my countries.yml file, so fixtures knows how to take care of this. However, this only works when you do not specify an ID value for the countries object. So I cannot assign USA's ID to be 1. But if I do not assign it to be 1, it ends up being some large value 8974343…which is kinda strange. Is there a way to get fixtures to auto-generate id's that are not super high? ….or is this ok?
Ruby-on-rails – Automatic associations in ruby on rails fixtures
fixturesrubyruby-on-rails
Related Question
- Ruby-on-rails – How to understand nil vs. empty vs. blank in Ruby
- Ruby-on-rails – Understanding the Rails Authenticity Token
- Ruby – How to write a switch statement in Ruby
- Ruby – How to check if a value exists in an array in Ruby
- Ruby-on-rails – Rails: How to rename a database column in a Ruby on Rails migration
- Ruby-on-rails – How to get the current absolute URL in Ruby on Rails
- Ruby – attr_accessor in Ruby
Best Solution
This is how you get an autogenerated id of the fixture label.