Polymorphic associations and hobo g migration

36 views
Skip to first unread message

Bob Sleys

unread,
Jul 12, 2011, 11:53:28 AM7/12/11
to hobo...@googlegroups.com
Running hobo 1.3 it appears that running hobo g migration doesn't work when there is a polymorphic association between models.

First here is the errror.

Hobo Command Line Interface 1.3.0
/home/bsleys/.rvm/gems/ruby-1.8.7-p352@HazMatTracking/bundler/gems/hobo-900179e80104/hobo/lib/generators/hobo/routes/router.rb:56:in `owner_routes': Hob routing error -- can't find reverse association for Sample#sample_test (e.g. the :has_many that corresponds to a :belongs_to) (Hobo::Error)

And my models, extra stuff clipped.

class Sample < ActiveRecord::Base
  hobo_model # Don't put anything above this
  fields do
    positive :boolean
    result   :string
    timestamps
  end
  belongs_to :sample_test, :polymorphic => true
  ....
end

class Asbestos < ActiveRecord::Base
  hobo_model # Don't put anything above this
  fields do
    name :string
    timestamps
  end
  belongs_to :material
  has_many :samples, :as => :sample_test
  ...
end

class Lead < ActiveRecord::Base
  hobo_model # Don't put anything above this
  fields do
    note :text
    timestamps
  end
  belongs_to :material
  has_many :samples, :as => :sample_test
  ...
end

class Pcb < ActiveRecord::Base
  hobo_model # Don't put anything above this
  fields do
    name :string
    notes :text
    timestamps
  end
  belongs_to :material
  has_many :samples, :as => :sample_test
  ...
end

kevinpfromnm

unread,
Jul 12, 2011, 12:53:05 PM7/12/11
to hobo...@googlegroups.com
I think you're getting the problem from the auto_actions_for, not the polymorphic bit.  though it may be having a problem making the auto_actions_for a polymorphic association.

Bob Sleys

unread,
Jul 12, 2011, 1:30:11 PM7/12/11
to hobo...@googlegroups.com
I believe you are correct.  I remove the auto_actions_for from the controller and the migration worked.  So now to just find a way around the auto_actions_for problem.

Bob

Matt Jones

unread,
Jul 12, 2011, 2:24:58 PM7/12/11
to hobo...@googlegroups.com

On Jul 12, 2011, at 11:53 AM, Bob Sleys wrote:

> Running hobo 1.3 it appears that running hobo g migration doesn't work when there is a polymorphic association between models.
>
> First here is the errror.
>
> Hobo Command Line Interface 1.3.0
> /home/bsleys/.rvm/gems/ruby-1.8.7-p352@HazMatTracking/bundler/gems/hobo-900179e80104/hobo/lib/generators/hobo/routes/router.rb:56:in `owner_routes': Hob routing error -- can't find reverse association for Sample#sample_test (e.g. the :has_many that corresponds to a :belongs_to) (Hobo::Error)
>

Actually, it looks like it's blowing up even before it gets there - this error is from the route generator that runs on startup. Judging from the data, it looks like you've got an auto_actions_for on the polymorphic association, which I don't believe will work out of the box...

--Matt Jones


Reply all
Reply to author
Forward
0 new messages