With two of my Rails models when I try to call the ActiveRecord
method select
it just returns the error object doesn't support #inspect
These models use the after_initialize
callback, so I suspect it has something to do with that.
I'm using the after_initialize
callback like this:
enum state: [ :archived, :active ]
after_initialize :state_init
after_initialize :date_init
def state_init
self.state ||= :active
end
def date_init
self.report_date ||= self.event ? self.event.event_date : Date.current
end
and I need to use the select
method to select records grouped by month using a field that has a date with Postgres
ModelName.select("date_trunc( 'month', report_date ) as month, count(*) as count").group('month')
Is there any way to work around this problem?