# An unknown number of elements

**URL:** <https://www.ruby-forum.com/t/an-unknown-number-of-elements/92613>\
**Category:** Rails\
**Created:** [April 21, 2007, 4:06pm UTC](https://www.ruby-forum.com/t/an-unknown-number-of-elements/92613 "2007-04-21T16:06:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![chriscole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5fc32e/32.png) [@chriscole](https://www.ruby-forum.com/u/chriscole)\
**Post date:** [April 21, 2007, 4:06pm UTC](https://www.ruby-forum.com/t/an-unknown-number-of-elements/92613/1 "2007-04-21T16:06:35Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![chriscole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5fc32e/32.png) [@chriscole](https://www.ruby-forum.com/u/chriscole)\
**Post date:** [April 22, 2007, 5:39pm UTC](https://www.ruby-forum.com/t/an-unknown-number-of-elements/92613/2 "2007-04-22T17:39:20Z")

</div>

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](mailto:removed_email_address@domain.invalid)
