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

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?

(snip)

On Nov 14, 2007, at 11:47 AM, [email protected] 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.