rake db:fixtures:load doesn't resolve properly label references for associations #884

Closed
lighthouse-import opened this Issue May 16, 2011 · 3 comments

Projects

None yet

3 participants

@lighthouse-import

Imported from Lighthouse. Original ticket at: http://rails.lighthouseapp.com/projects/8994/tickets/6495
Created by gamov - 2011-03-01 17:42:08 UTC

When using fixtures with "Label references for associations" (see doc activerecord/lib/active_record/fixtures.rb), the rake command rake db:fixtures:load fails to load the fixtures properly in the database. The DB column name is not translated properly and the field value isn't looked up and the label is put as the value instead of the id of the associated record.

Attached an app with label references in fixtures, just type rake db:fixtures:load and see it fails:

SQLite3::SQLException: table courses has no column named teacher: INSERT INTO "courses" ("subject", "teacher", "created_at", "updated_at", "id") VALUES ('Math', 'toto', '2011-03-01 16:52:15', '2011-03-01 16:52:15', 690422863)

With rails 3.0.5. Works with 2.3.10

@lighthouse-import

Imported from Lighthouse.
Comment by gamov - 2011-03-02 04:48:57 UTC

Weirdly, I've created this test application because my big application that I'm migrating to rails 3 couldn't load the fixtures properly; the same way as this test app.
Today, my big application loads the many fixtures with label references!?!

@gamov

For reference and help:
In the linked application, the problem is that the association belongs_to :teacher is not defined in the model therefore the fixtures cannot derive the foreign key name.

In my app, the problem was an unrelated but linked class to the currently loaded fixture had an error which prevent the fixture to derive its foreign key.

@GerryG

I just started having this problem. I checked my models and the associations are there, and it was working ...

Hmm, maybe I have something similar going on and someone is swallowing the exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment