【发布时间】:2009-09-25 08:06:06
【问题描述】:
我有两个具有 has_many 和 belongs_to 关联的类:
class Employee < ActiveRecord::Base
has_many :contracts
end
class Contract < ActiveRecord::Base
belongs_to :employee
end
我希望 Contract 类的#employee 方法返回的员工与自己相同,这意味着下面的单元测试会通过。
class EmployeeTest < ActiveSupport::TestCase
test "an object retrieved via a belongs_to association should be equal to itself" do
e = Employee.new
e.contracts << Contract.new
assert e.save
a = e.contracts[0].employee
assert a.equal? a
end
end
但是,它失败了。我不明白。这是 ActiveRecord 中的错误吗?
感谢您的帮助。
【问题讨论】:
标签: ruby-on-rails activerecord