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