In associations between different models, one can avoid setting foreign key IDs directly by using fixture names as in this answer. What about self-referencing associations, such as when using acts_as_tree? Trying this:
# categories.yml
forsale:
name: For Sale
parent_id: nil
books:
name: Books
parent: forsale
I get this error:
SQLite3::SQLException: table categories has no column named parent: INSERT INTO "categories" ("name", "parent") VALUES ('Books', 'forsale')
Is there any way to make one fixtures refence another in the same class without using explicit IDs?
Update:
Appending the class name between parentheses like for polymorphic belongs_to fixtures doesn't work either. Doing this:
books:
name: Books
parent: forsale (Category)
Produces a random parent_id
for books
instead of forsale
's ID.