Hi All, Would love to hear your input on this: I have a model called Demonstration. A Demonstration can take place on any, some or all of the days in a given week. i.e. Monday, Tuesday and Friday How should I setup my model(s) to support this relationship? Is there a preferred method?? Two ideas i''ve had: - Create a model named Days with a row for each day of the week. Create a days_demonstrations table and create a HABTM relationship - Use the built in Date::DAYNAMES that comes with Ruby. Create a field in the Demonstration table called ''days'' and store the supported days as a string: 0,3,5. Then break it up when it''s time to use them as check boxes in the view. thanks! -- Posted via http://www.ruby-forum.com/.
sir ziggles wrote:> Hi All, > > Would love to hear your input on this: > > I have a model called Demonstration. > > A Demonstration can take place on any, some or all of the days in a > given week. > > i.e. Monday, Tuesday and Friday > > How should I setup my model(s) to support this relationship? Is there a > preferred method?? > > > > > Two ideas i''ve had: > - Create a model named Days with a row for each day of the week. > Create a days_demonstrations table and create a HABTM relationship > > - Use the built in Date::DAYNAMES that comes with Ruby. Create a field > in the Demonstration table called ''days'' and store the supported days as > a string: 0,3,5. Then break it up when it''s time to use them as check > boxes in the view. > > > thanks! >I just use a boolean column for each day. Simplest thing that can possibly work and all that. -- Jack Christensen jackc-/SOt/BrQZzMOf2zXYvRtkodd74u8MsAO@public.gmane.org
2009/6/2 Jack Christensen <jackc-/SOt/BrQZzMOf2zXYvRtkodd74u8MsAO@public.gmane.org>:> > sir ziggles wrote: >> Hi All, >> >> Would love to hear your input on this: >> >> I have a model called Demonstration. >> >> A Demonstration can take place on any, some or all of the days in a >> given week. >> >> i.e. Monday, Tuesday and Friday >> >> How should I setup my model(s) to support this relationship? Is there a >> preferred method?? >> >> >> >> >> Two ideas i''ve had: >> - Create a model named Days with a row for each day of the week. >> Create a days_demonstrations table and create a HABTM relationship >> >> - Use the built in Date::DAYNAMES that comes with Ruby. Create a field >> in the Demonstration table called ''days'' and store the supported days as >> a string: 0,3,5. Then break it up when it''s time to use them as check >> boxes in the view. >> >> >> thanks! >> > I just use a boolean column for each day. Simplest thing that can > possibly work and all that. > > -- > Jack Christensen > jackc-/SOt/BrQZzMOf2zXYvRtkodd74u8MsAO@public.gmane.org >I think I would do the same, then you can easily have a set of checkboxes for the user to specify the days if that is appropriate. Colin> > > >
Colin Law wrote:> 2009/6/2 Jack Christensen <jackc-/SOt/BrQZzMOf2zXYvRtkodd74u8MsAO@public.gmane.org>: >>> >>> Create a days_demonstrations table and create a HABTM relationship >> possibly work and all that. >> >> -- >> Jack Christensen >> jackc-/SOt/BrQZzMOf2zXYvRtkodd74u8MsAO@public.gmane.org >> > > I think I would do the same, then you can easily have a set of > checkboxes for the user to specify the days if that is appropriate. > > ColinColin, i''m sorry but your response (at least on ruby-forum.com) is quoting both of the potential methods i had mentioned... which one were you saying is the preferred way? and big thanks to jack and colin for taking time to respond! -- Posted via http://www.ruby-forum.com/.
2009/6/2 sir ziggles <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > Colin Law wrote: >> 2009/6/2 Jack Christensen <jackc-/SOt/BrQZzMOf2zXYvRtkodd74u8MsAO@public.gmane.org>: >>>> >>>> Create a days_demonstrations table and create a HABTM relationship >>> possibly work and all that. >>> >>> -- >>> Jack Christensen >>> jackc-/SOt/BrQZzMOf2zXYvRtkodd74u8MsAO@public.gmane.org >>> >> >> I think I would do the same, then you can easily have a set of >> checkboxes for the user to specify the days if that is appropriate. >> >> Colin > > Colin, i''m sorry but your response (at least on ruby-forum.com) is > quoting both of the potential methods i had mentioned... > > which one were you saying is the preferred way?I think the crucial text has been snipped. My comment is immediately after Jack Christensen''s. My intention was to indicate that I would do it the same way as him. I should have been a bit more explicit. Colin> > > and big thanks to jack and colin for taking time to respond! > -- > Posted via http://www.ruby-forum.com/. > > > >
ah got ya. thinking out loud here... The Demonstration table might look like: --------------- | Demonstration | --------------- | id:integer | | title:string | | descript:text | | mon:boolean | | tues:boolean | | wed:boolean | | etc etc | --------------- The only drawback I can see is that if I decided to add something like a Presentation model that also occurs on various days in the week I would have to add those same day columns to the Presentation model and it doesn''t seem very DRY? -- Posted via http://www.ruby-forum.com/.
2009/6/2 sir ziggles <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > ah got ya. > > thinking out loud here... > > The Demonstration table might look like: > --------------- > | Demonstration | > --------------- > | id:integer | > | title:string | > | descript:text | > | mon:boolean | > | tues:boolean | > | wed:boolean | > | etc etc | > --------------- > > > The only drawback I can see is that if I decided to add something like a > Presentation model that also occurs on various days in the week I would > have to add those same day columns to the Presentation model and it > doesn''t seem very DRY? >I think if you wanted day selection in more than one model you would do it using a polymorphic model relationship (see http://railscasts.com/episodes/154-polymorphic-association for example). Still using a set of booleans in the DaySelectable model or whatever you call it. Alternatively, dependent on how similar Demonstration and Presentation were they could be combined into one model or use Single Table Inheritance. Colin> -- > Posted via http://www.ruby-forum.com/. > > > >
Jack Christensen wrote:> sir ziggles wrote:>> I have a model called Demonstration. >> >> A Demonstration can take place on any, some or all of the days in a >> given week. >> >> i.e. Monday, Tuesday and Friday >> >> How should I setup my model(s) to support this relationship?> I just use a boolean column for each day.Is there typically any space penalty (or advantage) for separate, boolean columns, relative to an integer bit-field?
god, i love railscasts :) checking it out now. thank you again colin! -- Posted via http://www.ruby-forum.com/.
2009/6/2 Jeff Schwab <jeff-0DHsjr3A8/m6BbymS3xAUA@public.gmane.org>:> > .... > > Is there typically any space penalty (or advantage) for separate, > boolean columns, relative to an integer bit-field? >Yes I am sure there is a space penalty. Disk space and processor power are cheap, skilled manpower is expensive. I would do it the way that is easiest to implement and maintain and worry about efficiency only if it becomes a problem (which it usually will not), and I am old enough to remember writing in machine code and worrying about every byte and processor cycle. Colin