开发者

Rails Foxy Fixtures throwing unknown column error

开发者 https://www.devze.com 2022-12-13 06:37 出处:网络
I am using dynamic fixtures and whenever I run my tests I am getting an error that thinks my association is a column, when it should be owner_id:

I am using dynamic fixtures and whenever I run my tests I am getting an error that thinks my association is a column, when it should be owner_id:

ActiveRecord::StatementInvalid: Mysql::Error: Unknown column 'owner' in 'field list': INSERT INTO `companies` (`custom_host`, `name`, `created_at`, `updated_at`, `api_key`, `id`, `subdomain`, `owner`) VALUES ('testerapp.com', 'Some Company', '2009-11-29 21:39:29', '2009-11-29 21:39:29', 'ae2b1fca515949e5d54fb22b8ed95575', 467557389, 'some_company', 'garrett')

In my companies.yml file I have this:

some_company:
  name: Some Company
  subdomain: some_company
  custom_host: testerapp.com
  api_key: <%= "testing".to_md5 %>
  owner: garrett

And users.yml:

garrett:
  company: some_company
  login: garrett
  email: email@me.com
  ...
  locale: en
  role_name: owner

Here are my models as well:

class Company < ActiveRecord::Base
  has_one :owner, :class_name => "User"
  has_many :users
  validates_associated :owner
end

cl开发者_如何转开发ass User < ActiveRecord::Base
  belongs_to :company
end

Could my problem be because I am associating User twice within Company? This is making testing really hard right now, and I was hoping someone could shine some light as to why it isn't reading my associations correctly.

Thanks!


Your has_one :owner should be belongs_to :owner

0

精彩评论

暂无评论...
验证码 换一张
取 消