# Attempting to use fixtures with STI and references

**URL:** <https://www.ruby-forum.com/t/attempting-to-use-fixtures-with-sti-and-references/147690>\
**Category:** Rails\
**Created:** [September 4, 2008, 9:29am UTC](https://www.ruby-forum.com/t/attempting-to-use-fixtures-with-sti-and-references/147690 "2008-09-04T09:29:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![darrikmazey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/82dd89/32.png) [@darrikmazey](https://www.ruby-forum.com/u/darrikmazey)\
**Post date:** [September 4, 2008, 9:29am UTC](https://www.ruby-forum.com/t/attempting-to-use-fixtures-with-sti-and-references/147690/1 "2008-09-04T09:29:53Z")

</div>

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.
