Rails Foxy Fixtures投掷未知列错误
-
08-07-2019 - |
题
我正在使用动态灯具,每当我运行我的测试时,我收到一个错误,认为我的关联是一个列,当它应该是 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
我的问题可能是因为我在 Company
中两次关联 User
?这使得测试现在变得非常困难,我希望有人能够解释为什么它没有正确地阅读我的关联。
谢谢!
解决方案
您的has_one:所有者应为belongs_to:owner
不隶属于 StackOverflow