Rails 3 中关联的标记装置损坏 [英] Labeled fixtures for associations in Rails 3 broken

查看:29
本文介绍了Rails 3 中关联的标记装置损坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

升级到 Rails 3 后,引用其他标记的装置(用于关系)的装置停止工作.夹具标签被解释为字符串,而不是找到具有该名称的实际夹具.

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.

示例:

# Dog.yml

sparky:
  name: Sparky
  owner: john

# Person.yml

john:
  name: John

狗属于"人的地方.

错误信息是:

SQLite3::SQLException: 表 Dogs 没有名为owner"的列

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

推荐答案

尝试

# Dog.yml

sparky:
  name: Sparky
  owner: john (Person)

# Person.yml

john:
  name: John

请参阅http://api.rubyonrails.org/classes/的多态belongs_to"部分Fixtures.html

这篇关于Rails 3 中关联的标记装置损坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆