Hi, On Sep 27, 2009, at 4:57 PM, ccuilla wrote: > I've been trying to update my Rails project to the new "foxy fixtures" > approach but have run into the following (vexing) problem. > > My models looks like this: > > class Account < ActiveRecord::Base > has_one :administrator, :class_name => "User" > end > > class User < ActiveRecord::Base > belongs_to :account > end > > > When I do this in the fixtures: > > accounts.yml... > > valid_account: > administrator: valid_user > > > users.yml... > > valid_user: > account: valid_account > > > I get the following: > > ActiveRecord::StatementInvalid: Mysql::Error: Unknown column > 'administrator' in 'field list': INSERT INTO `accounts` (... > > Is there a way to tell the fixture that "administrator" should > reference the User model?
Fixture entries are intentionally tied to the structure of the DB. Since that's the case, the association goes on the side with the foreign key. In your situation, the users table has an account_id field, and the accounts table has nothing. So: # users.yml default: account: default ...will work fine with no annotation on the account side. On a more general note, I don't think your keys are in the right place. I'd have an administrator_id on accounts with a belongs_to pointing at users. ~ j. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---