【发布时间】:2014-08-02 09:55:18
【问题描述】:
我的用户模型:
class User < ActiveRecord::Base
has_many :articles, :dependent => :destroy
end
文章型号:
class Article < ActiveRecord::Base
belongs_to :user
end
文章夹具:
one:
url: http://www.google.com/
title: Sample Title
user: default
用户夹具:
default:
email: user@example.com
name: Test User
在测试用例中尝试Article.first.user 效果很好,但如果我尝试在我的用户夹具中使用以下内容来获得相反的关系:
default:
email: user@example.com
name: Test User
articles: one
我收到以下错误:
ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR: column "articles" of relation "users" does not exist
【问题讨论】:
-
您不需要
articles: one。它应该会自动运行。 -
@SampritiPanda 你能把它放在答案中吗?非常感谢。
标签: ruby-on-rails relationship fixtures