# New Foxy Fixtures (Rails 2) & STI (Single Table Inheritance)

**URL:** <https://www.ruby-forum.com/t/new-foxy-fixtures-rails-2-sti-single-table-inheritance/120217>\
**Category:** Rails\
**Created:** [November 14, 2007, 8:48pm UTC](https://www.ruby-forum.com/t/new-foxy-fixtures-rails-2-sti-single-table-inheritance/120217 "2007-11-14T20:48:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 14, 2007, 8:48pm UTC](https://www.ruby-forum.com/t/new-foxy-fixtures-rails-2-sti-single-table-inheritance/120217/1 "2007-11-14T20:48:17Z")

</div>

I’ve got some problems right now using the new model for relationships  
in fixtures (by label, not by id) and STI. What I’ve got, is a couple  
of models:

Attachment  
–\> FileDownload  
Version

Version has\_one file\_download with file\_download\_id on the versions  
table

In my fixtures, I have two FileDownloads in my attachments.yml like  
so:

hemingway\_alpha\_zip:  
size: 100  
filename: hemingway\_alpha.zip  
content\_type: application/zip  
type: FileDownload  
project: hemingway

now, in my versions.yml, I have:

alpha:  
name: Alpha 1  
revision: 2  
description: this is the first alpha release for hemingway!  
project: hemingway  
file\_download: hemingway\_alpha\_zip  
created\_at: \<%= (Time.now - 5.days).to\_formatted\_s(:db) %\>

The problem I’m having is that it’s trying to put file\_download into a  
column in versions when I run rake test:units

ActiveRecord::StatementInvalid: Mysql::Error: #42S22Unknown column  
‘file\_download’ in ‘field list’: INSERT INTO `versions`  
(`file_download`, `name`, `project_id`, `updated_at`, `id`,  
`revision`, `description`, `created_at`) VALUES  
(‘hemingway\_alpha\_zip’, ‘Alpha 1’, 2980859, ‘2007-11-14 11:23:26’,  
296151536, 2, ‘this is the first alpha release for hemingway!’,  
‘2007-11-09 11:23:26’)

Now, I’ve got two questions:

a) How can I make it think that file\_download is a relationship and  
not a field?  
b) How can I get that label-hash id manually? (i.e. alpha --\>  
296151536) in case I just need to hack it in manually?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 15, 2007, 12:04am UTC](https://www.ruby-forum.com/t/new-foxy-fixtures-rails-2-sti-single-table-inheritance/120217/2 "2007-11-15T00:04:33Z")

</div>

(snip)

On Nov 14, 2007, at 11:47 AM, removed\_email\_address@domain.invalid wrote:

> a) How can I make it think that file\_download is a relationship and  
> not a field?  
> b) How can I get that label-hash id manually? (i.e. alpha --\>  
> 296151536) in case I just need to hack it in manually?

For (a), it sounds like you’re missing the other half of your has\_one  
relationship. Do you have an appropriate belongs\_to declared? The  
current fixture implementation expects has\_one relationships to be  
specified on the belongs\_to side, identically to has\_many.

For (b), what you’re looking for is Fixtures.identify, e.g.,

foo:  
bar\_id: \<%= Fixtures.identify(:label) %\>

~ j.
