Search code examples
ruby-on-railssqlitekeyyamlfixtures

Confusion with inconsistent fixtures


something wrong with my fixtures is causing them to behave strangely. The "Score" model joins "Users" with "Assignments" with additional columns for some other information. The fixture looks like this:

Score.yml

one:
    assignment: pythag
    position: 2
    student: natalie
    points: 75

This produces an error: ActiveRecord::Fixture::FixtureError: table "scores" has no column named "assignment".

The error makes sense, because my score schema includes a column named, ":student_id", not a column named ":student".

But I'm confused because all of my other fixtures use the same type of relative key that I'm trying to use here. For example, my "assignments" fixtures refer to "seminar," rather than "seminar_id."

assignment.yml

one:
  position: 1
  name: Pythag
  possible: 100
  seminar: one

This allows me to easily refer to a specific fixture from my seminars.yml file, so that I don't need to find the strange id number that rails produces. I'd like to do the same with my scores fixtures.

Any ideas on what could cause one fixture to need absolute column names, while the rest of them readily accept relative column names?

Thank you in advance for any insight.

-Jeff


Solution

  • You should define the association in your Score model. Take a look at the documentation, especially this part:

    Active Record reflects on the fixture's model class, finds all the belongs_to associations, and allows you to specify a target label for the association (monkey: george) rather than a target id for the FK (monkey_id: 1)