Here is a part of type system in my Rails app :
daytime : just an integer >= 0 and < 86400
dayinterval : a pair of daytimes, where first one is less than last
dayschedule : zero or more (non-intersecting) dayintervals
weekschedule : seven dayschedules.
DayInterval, DaySchedule and WeekSchedule are also models to be stored
in the database. To save on association(join) tables, DaySchedule has
text column “intervals” where a serialized array of DayInterval ids is
stored, and WeekSchedule has text column “days” to store a serialized
array of DaySchedule ids.
And so, my question is, how to leverage Rails facilities to express
these relations in short way ? I.e., I would like .intervals method to
return me not just Array of integers, but make it know that these
integers are references to DayInterval ids and so , << and = have
to convert these ids to DayIntervals and vs-vrs. Currently I have had
to write this logic by hand, and so far it looks quite repetitive.
Should I dive into heavy metaprogramming to factor out the common
parts, or Rails (v2) could offer something ready-made to help me with
my problem ?
Thank you in advance for your reply.