首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Rails:无法使用STI (未定义的方法`reflect_on_all_associations')加载表的夹具

Rails:无法使用STI (未定义的方法`reflect_on_all_associations')加载表的夹具
EN

Stack Overflow用户
提问于 2010-12-10 03:51:22
回答 2查看 1.6K关注 0票数 2

我不能装载使用STI的表的夹具。

当我调用FIXTURES=schools rake db:fixtures:load时,会得到以下错误:

代码语言:javascript
复制
undefined method `reflect_on_all_associations' for Object:Class

其他夹具负载良好,即通过调用FIXTURES=committes rake db:fixtures:load

  • The创建夹具。

这里是我的学校迁移:

代码语言:javascript
复制
class CreateSchools < ActiveRecord::Migration
  def self.up
    create_table :schools do |t|
      t.string :name
      t.string :type
      t.string :street
      t.string :city
      t.string :province
      t.timestamps
    end
  end
...
end

我有几个模型文件,即school.rb

代码语言:javascript
复制
class School < ActiveRecord::Base
end

secondary_school.rb

代码语言:javascript
复制
class SecondarySchool < School
end

下面是堆栈跟踪:

代码语言:javascript
复制
undefined method `reflect_on_all_associations' for Object:Class
/home/loranaw/ruby/gems/gems/activerecord-2.3.10/lib/active_record/fixtures.rb:597:in `insert_fixtures'
/home/loranaw/ruby/gems/gems/activerecord-2.3.10/lib/active_record/fixtures.rb:568:in `each'
/home/loranaw/ruby/gems/gems/activerecord-2.3.10/lib/active_record/fixtures.rb:568:in `insert_fixtures'
/home/loranaw/ruby/gems/gems/activerecord-2.3.10/lib/active_record/fixtures.rb:512:in `create_fixtures'
/home/loranaw/ruby/gems/gems/activerecord-2.3.10/lib/active_record/fixtures.rb:512:in `each'
/home/loranaw/ruby/gems/gems/activerecord-2.3.10/lib/active_record/fixtures.rb:512:in `create_fixtures'
/home/loranaw/ruby/gems/gems/activerecord-2.3.10/lib/active_record/connection_adapters/abstract/database_statements.rb:136:in `transaction'
/home/loranaw/ruby/gems/gems/activerecord-2.3.10/lib/active_record/fixtures.rb:510:in `create_fixtures'
/home/loranaw/ruby/gems/gems/activerecord-2.3.10/lib/active_record/connection_adapters/mysql_adapter.rb:267:in `disable_referential_integrity'
/home/loranaw/ruby/gems/gems/activerecord-2.3.10/lib/active_record/fixtures.rb:501:in `create_fixtures'
/home/loranaw/ruby/gems/gems/activerecord-2.3.10/lib/active_record/base.rb:1482:in `silence'
/home/loranaw/ruby/gems/gems/activerecord-2.3.10/lib/active_record/fixtures.rb:500:in `create_fixtures'
/home/loranaw/ruby/gems/gems/rails-2.3.10/lib/tasks/databases.rake:223
/home/loranaw/ruby/gems/gems/rails-2.3.10/lib/tasks/databases.rake:222:in `each'
/home/loranaw/ruby/gems/gems/rails-2.3.10/lib/tasks/databases.rake:222

一些样本YML:

代码语言:javascript
复制
--- 
schools_7133: 
  city: Nahanni Butte
  name: Charles Yohin School
  created_at: 2010-11-26 02:36:39
  grade_range: K-10
  latitude: "61.03349"
  country: CA
  updated_at: 0000-00-00 00:00:00
  postal_code: "X0E 0N0"
  url: 
  street: ""
  id: "9682"
  type: SecondarySchool
  fax: (867) 602-2202
  phone: (867) 602-2200
  funding: 
  longitude: "-123.38642"
  school_type: 
  province: NT
  email: 
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-12-10 16:20:01

问题的结果是其中一个记录的类型为空白/空值。确保STI表中的每一行都有一个类型。

票数 0
EN

Stack Overflow用户

发布于 2010-12-10 04:08:14

School对象有一个名为type的字段,用于单表继承。重新命名该字段可以解决这个问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4405481

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档