Rails loading fixtures with wrong foreign keys Rails loading fixtures with wrong foreign keys sqlite sqlite

Rails loading fixtures with wrong foreign keys


I think rails is getting in a muddle with your class/fixtures name for series. It tries to look for a model class named Series because it struggles to singularize your plural name. (Series being a word in english where the plural is the same as the singular).

I strongly suspect that the Serie instance in your database is nothing to do with your fixture load at all and is instead an instance that has been created via another method.

The serie_id used in your events fixtures is correct. The id that is used is calculated using:

> ActiveRecord::FixtureSet.identify(:Serie1)=> 627975337

which you can see is the same as the value used in your fixtures.

So, a solution, you can either get into the bowels of active record and override the rake task that loads the fixtures - or you can define your singular/plural versions of "serie"/"series" to be what you want rather than what rails is guessing. In config/application.rb or an initializer you can add:

ActiveSupport::Inflector.inflections do |inflect|  inflect.irregular 'serie', 'series'end