An unknown number of elements


#1

Hi all!
I have a model (Show) than can have an unknown number of dates. And a
date can have an unknown number of shows. Making a Date model seems
icky, espicially since I would have to probably write a lot of glue code
to get the many-many to work easily. I was thinking maybe storing a
Marshaled array of Time objects in a text field, but that isn’t very
clean either… Any Ideas?


#2

The only major concern with is how you’re going to efficiently perform
queries for shows occurring on particular dates. If you stored the
dates as a comma-separated list of strings, you could make these kinds
of queries a bit more efficient:

class Show
def for_date(date)
# assuming trailing commas…
find(:all, :conditions => [“date LIKE ‘%?,%’”, date.strftime("%Y/
%m/%d")])
end
end

You’re sorta screwed if you want to find shows within a date range
though. Also, you have to load and re-save the entire column just to
add or remove a date – this is probably ok if there are less than a
hundred dates…

Using a many-to-many isn’t THAT hard. You get a lot of power with it
– and the amount of glue code you need to write should be minimal.
In this case it seems to be the cleaner solution…

On Apr 21, 10:06 pm, Chris C. removed_email_address@domain.invalid