【发布时间】:2011-01-17 04:43:49
【问题描述】:
在不同模型之间的关联中,可以避免直接使用 this answer 中的夹具名称来设置外键 ID。自引用关联又如何呢,例如在使用acts_as_tree 时?试试这个:
# categories.yml
forsale:
name: For Sale
parent_id: nil
books:
name: Books
parent: forsale
我收到此错误:
SQLite3::SQLException: table categories has no column named parent: INSERT INTO "categories" ("name", "parent") VALUES ('Books', 'forsale')
有没有什么方法可以在不使用显式 ID 的情况下让一个灯具引用同一类中的另一个灯具?
更新:
在polymorphic belongs_to 固定装置的括号之间附加类名也不起作用。这样做:
books:
name: Books
parent: forsale (Category)
为books 生成一个随机的parent_id,而不是forsale 的ID。
【问题讨论】:
标签: ruby-on-rails unit-testing fixtures