Labeled fixtures for associations in Rails 3 broken

孤者浪人 提交于 2021-02-06 10:19:45

问题


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'


回答1:


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




回答2:


try this:

sparky:
  name: Sparky
  owner: john (Person)


来源:https://stackoverflow.com/questions/3026654/labeled-fixtures-for-associations-in-rails-3-broken

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!