简体   繁体   中英

Labeled fixtures for associations in Rails 3 broken

After upgrading to Rails 3, fixtures that refer to other labelled fixtures (for relationships) stop working. Instead of finding the actual fixture with that name, the fixture label is interpreted as a string.

Example:

# Dog.yml

sparky:
  name: Sparky
  owner: john

# Person.yml

john:
  name: John

Where Dog "belongs to" person.

The error message is:

SQLite3::SQLException: table dogs has no column named 'owner'

Try

# Dog.yml

sparky:
  name: Sparky
  owner: john (Person)

# Person.yml

john:
  name: John

See the "polymorphic belongs_to" section of http://api.rubyonrails.org/classes/Fixtures.html

try this:

sparky:
  name: Sparky
  owner: john (Person)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM