views:

296

answers:

2

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?
    acting_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 http://stackoverflow.com/questions/646391/ruby-on-rails-single-table-inheritance-sti-and-unit-test-problem-with-postgres, 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.0RC1

Any suggestions?

A: 

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
St.Woland
Yup. Same behavior. Not sure why it worked for you... :(
organicveggie
+1  A: 

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).

organicveggie
Note that this was fixed on 1/24/2010 and is in the latest release candidate.
organicveggie