Rails object inheritence with belongs_to

Posted by Rabbott on Stack Overflow See other posts from Stack Overflow or by Rabbott
Published on 2010-06-14T16:50:01Z Indexed on 2010/06/14 16:52 UTC
Read the original article Hit count: 203

I have a simple has_many/belongs_to relationship between Report and Chart. The issue I'm having is that my Chart model is a parent that has children.

So in my Report model I have

class Report < ActiveRecord::Base
  has_many :charts
end

And my Chart model is a parent, where Pie, Line, Bar all inherit from Chart. I'm not sure where the belongs_to :report belongs within the chart model, or children of chart model. I get errors when I attempt to access chart.report because the object is of type "Class"

undefined local variable or method `report' for #< Class:0x104974b90>

The Chart model uses STI so its pulling say.. 'Pie' from the chart_type column in the charts table.. what am I missing?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about inheritance