【问题标题】:Rails and Hobo with Single Table Inheritance problem带有单表继承问题的 Rails 和 Hobo
【发布时间】:2011-01-08 00:06:41
【问题描述】:

在使用干净的数据库为我的 Hobo 项目运行 db:setup 时出现错误。我有两个模型,A 和 B,其中 B 通过单表继承扩展 A。创造一切都有效。但是如果我从一个新的数据库开始,rake 会失败并出现错误:

$ rake db:setup
...
rake aborted!
Table as does not exist

这是我重现此问题的步骤。首先,创建 Hobo 应用:

$ hobo testproject

创建第一个模型,A

$ ruby script/generate hobo_model_resource a name:string type:string

设置database.yml,生成并执行迁移:

$ ruby script/generate hobo_migration

创建第二个模型,B

$ruby script/generate hobo_model_resource b

编辑B 模型以扩展A

class B < A

  # --- Permissions --- #
  def create_permitted?
    acting_user.administrator?
  end

  def update_permitted?
    acting_user.administrator?
  end

  def destroy_permitted?
    acting_user.administrator?
  end

  def view_permitted?(field)
    true
  end
end

生成并运行迁移:

$ ruby script/generate hobo_migration

瞧。一切正常。现在,如果我删除所有表并运行db:setup,它会失败:

$ rake db:setup
...
rake aborted!
Table as does not exist

按照Ruby on Rails Single Table Inheritance (STI) and unit test problem (with PostgreSQL) 的建议,我尝试删除test/fixtures/as.ymltest/fixtures/bs.yml,但这没有帮助。

流浪汉 0.9.103
导轨 2.3.5
耙 0.8.7
jruby 1.4.0RC1

有什么建议吗?

【问题讨论】:

    标签: ruby-on-rails ruby migration single-table-inheritance hobo


    【解决方案1】:

    我按照您的所有步骤进行操作,一切正常。你试过rake db:schema:load吗?

    hobo 0.9.104
    rails 2.3.5
    rake 0.8.6
    ruby 1.8.6
    

    【讨论】:

      【解决方案2】:

      看起来这是 Hobo 中的一个错误:

      http://groups.google.com/group/hobousers/browse_thread/thread/2160e78762791946

      根据马特琼斯的说法:

      跟踪具有自动范围代码,试图查看inherited_without_inheritable_attributes 是否是一列,该列命中
      DB 和死。

      他建议添加:

      return unless table_exists? 
      

      column 方法的最开始处(hobofields/lib/hobo_fields/model_extensions.rb 的第 211 行)。

      【讨论】:

      • 请注意,此问题已于 2010 年 1 月 24 日修复,并且在最新的候选版本中。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多