Rails object inheritence with belongs_to
- by Rabbott
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?