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
Basically, it looks like this:
class Note < ActiveRecord::Base
class ProjectNote < Note
has_one :reference, :class_name => 'Project'
class ClientNote < Note
has_one :reference, :class_name => 'Client'
Then in test/fixtures/notes.yml, I have:
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"
I'm not 100% positive what I'm attempting to do is even possible, but
I would appreciate whatever help / advice anyone can offer.
DMT Programming, LLC.