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

These associations look like they might be backwards.

> 
> 
> 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` (...

Well, yeah.  According to your associations, the accounts table does not 
have an administrator_id field, and that's all that fixtures work with.

> 
> Is there a way to tell the fixture that "administrator" should
> reference the User model?

Probably not.  You've just discovered the fundamental brokenness of 
fixtures: altough they appear to deal with AR classes and fields, in 
fact the abstraction is quite leaky and the fixtures are tied fairly 
directly to the DB.

This behavior is a misfeature of Rails.  The solution is quite simple: 
avoid fixtures completely.  Use Machinist or something similar instead.

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
mar...@marnen.org
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to