Given a migration
class CreateTalks < ActiveRecord::Migration
def self.up
create_table :talks do |t|
t.integer :duration_hours
t.integer :duration_minutes
end
end
def self.down
drop_table :talks
end
end
and model
class Talk < ActiveRecord::Base
end
and object
class Duration
attr_accessor :hours, :minutes
end
how do I map the duration_hours and duration_minutes columns to a Duration property in Talk so that I can do
d = Talk.first.duration
hours = d.hours
minutes = d.minutes
I'm aware that in this case I could translate the hours and minutes into seconds and store these in a single column but I'm looking to understand how I could achieve this type of mapping with ActiveRecord.