我正在使用动态装置,每当我运行测试时,我都会收到一个错误,认为我的关联是一列,它应该是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
吗?这使得测试现在变得非常困难,我希望有人能阐明为什么它没有正确读取我的关联。
谢谢!