Forum: Ruby on Rails An unknown number of elements

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Chris C. (Guest)
on 2007-04-21 18:06
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?
Eden L. (Guest)
on 2007-04-22 19:39
(Received via mailing list)
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/

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>
This topic is locked and can not be replied to.