2010-01-21 78 views
1

我在为我的Hobo项目运行db:setup时出现错误,它带有干净的数据库。我有两个模型,A和B,其中B通过单表继承来扩展A.创建一切正常。但是,如果我从新的数据库开始,耙机将失败,并显示以下错误:Rails和Hobo单表继承问题

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

以下是我重现此问题的步骤。首先,创建流浪汉应用:

$ 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

有什么建议?

回答

1

看起来像它在流浪汉中的错误:

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

根据马特·琼斯:

The trace has the automatic scope code trying to see if inherited_without_inheritable_attributes is a column, which hits the
DB and dies.

他建议增加:

return unless table_exists? 

在很搁g的column方法(hobofields/lib/hobo_fields/model_extensions.rb的第211行)。

+0

请注意,这是修正于2010年1月24日,并在最新的候选版本。 – organicveggie 2010-02-11 16:34:58

0

我遵循了你所有的步骤,并且一切正常。你有没有试过rake db:schema:load

hobo 0.9.104 
rails 2.3.5 
rake 0.8.6 
ruby 1.8.6 
+0

是。同样的行为。不知道为什么它为你工作... :( – organicveggie 2010-01-23 15:35:29