I'm getting an error when running db:setup
for my Hobo project with a clean database. I have two models, A and B, where B extends A through single-table-inheritance. Creating everything works. But if I start with a fresh database, rake fails with an error:
$ rake db:setup
...
rake aborted!
Table as does not exist
Here are the steps I went through to reproduce this. First, create the Hobo app:
$ hobo testproject
Create the first model, A
:
$ ruby script/generate hobo_model_resource a name:string type:string
Setup database.yml, generate and execute the migration:
$ ruby script/generate hobo_migration
Create the second model, B
:
$ruby script/generate hobo_model_resource b
Edit the B
model to extend A
:
class B < A
# --- Permissions --- #
def create_permitted?
acting_user.administrator?
end
def update_permitted?
acting_user.administrator?
end
def destroy_permitted?
开发者_如何学JAVAacting_user.administrator?
end
def view_permitted?(field)
true
end
end
Generate and run the migration:
$ ruby script/generate hobo_migration
Voila. All works fine. Now, if I delete all the tables and run db:setup
, it fails:
$ rake db:setup
...
rake aborted!
Table as does not exist
Following the suggestions at Ruby on Rails Single Table Inheritance (STI) and unit test problem (with PostgreSQL), I tried removing test/fixtures/as.yml
and test/fixtures/bs.yml
, but that didn't help.
hobo 0.9.103
rails 2.3.5 rake 0.8.7 jruby 1.4.0RC1Any suggestions?
Looks like it's a bug in Hobo:
http://groups.google.com/group/hobousers/browse_thread/thread/2160e78762791946
According to Matt Jones:
The trace has the automatic scope code trying to see if inherited_without_inheritable_attributes is a column, which hits the
DB and dies.
He suggests adding:
return unless table_exists?
at the very beginning of the column
method (line 211 of hobofields/lib/hobo_fields/model_extensions.rb
).
I followed all of your steps, and everything worked fine. Have you tried rake db:schema:load
?
hobo 0.9.104
rails 2.3.5
rake 0.8.6
ruby 1.8.6
精彩评论