代码之家  ›  专栏  ›  技术社区  ›  Garrett

Rails Foxy Fixtures抛出未知列错误

  •  1
  • Garrett  · 技术社区  · 16 年前

    我使用的是动态装置,每当我运行测试时,我都会收到一个错误,认为我的关联是一列,而它应该是一列 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')
    

    在我的 companies.yml

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

    及 users.yml :

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

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

    我的问题可能是因为我在交往吗 User 两次内 Company ? 这使得现在的测试非常困难,我希望有人能解释一下为什么它不能正确解读我的关联。

    1 回复  |  直到 16 年前
        1
  •  2
  •   Mike    16 年前

    您的has\u one:owner应该属于:owner