Hello.
I’m attempting to use STI for a class that contains a reference_id
field. However, the class_name of the reference isn’t known in the
base class because each subclass uses a different reference
class_name.
Basically, it looks like this:
class Note < ActiveRecord::Base
end
class ProjectNote < Note
has_one :reference, :class_name => ‘Project’
end
class ClientNote < Note
has_one :reference, :class_name => ‘Client’
end
Then in test/fixtures/notes.yml, I have:
client_note:
reference: my_client
project_note:
reference: my_project
This works fine (and I define helpers for the class to access their
reference), but when it comes to fixtures, I’m stumped. When rails
tries to load the fixtures, I get an error about an 'unknown column
“reference” in “field list” for the “notes” table, and according to
the SQL it’s trying to insert the name of the Client fixture into the
“reference” field, instead of using the id in the “reference_id”
field.
I’m not 100% positive what I’m attempting to do is even possible, but
I would appreciate whatever help / advice anyone can offer.
Thanks,
Darrik Mazey
DMT Programming, LLC.