Thanks for the help.  I'm going to write my thought process here real quick
in case someone else gets caught up on the same thing I did...

Since I was so focused on the concept of 'dates of availability' or their
converse 'black out dates', i let my mind get hung up on the idea that the
date itself needed modeling and that I therefore had a many-to-many
relationship.  I was imagining all the rooms that might be blacked out on
every third monday of each month, for example.

In fact, when I first started reading your solution, I thought "no, this
isn't right, I'm not deailing with bookings, I'm trying to deal with
black-out-dates"... and then i had the aha moment: If I think of 'black out
date' as an entity, then a 'black out date' can belong to a room.  From
there on out, problem solved just ask you describe.

Thanks again,
--Jon


On Mon, Oct 5, 2009 at 11:43 PM, Guyren G Howe <[email protected]> wrote:

>
> On Oct 5, 2009, at 22:33 , Jonathan Christensen wrote:
>
> > I've been looking around the internet and I don't see an obvious
> > good way to do what I'd like to do, so I thought I'd ask the group...
> >
> > I have an object, lets call it Room, that has many dates of
> > availability.  And conversely, on any given day of the year, there
> > may be many Rooms available.
> >
> > I'm trying to decide the best way to model this with ActiveRecord.
> > From a db perspective, it seems like it would be easy to just have a
> > table called rooms_days (or something like that) that has two
> > columns.  room_id:int and day:date.
> >
> > But because of my lack of experience, I'm not quite sure whether
> > this is sufficient and how to model it in my ActiveRecord classes.
> > I started to imagine saying the Room has_and_belong_to_many :days.
> > but then I don't have a model called Day, and I don't really want to
> > make a table that has only one date column in it because that would
> > add an additional join that seems unnecessary.
> >
> > I think maybe there's some way to make a Day model, but not have a
> > table underneath it, but still tell it to update the RoomDates table
> > via the association.  Does anyone have experience trying something
> > like this?
>
>
> rooms table with room names.
>
> bookings table with room_id and date: unique index on the pair, and if
> you search on both date and room and there are a lot of bookings, you
> may want the reverse index also, but don't do that until you find it's
> too slow without the index.
>
> You assume that if a room-date pair doesn't appear in that table, it
> is not booked.
>
> You can use joins to find booked rooms, outer joins to find unbooked
> rooms, and a union of the two (or any of several other tactics) to
> give you all your rooms and whether they're booked given various date
> conditions or room conditions.
>
> Should work pretty well.
>
> Regards,
>
> Guyren G Howe
> Relevant Logic LLC
>
> guyren-at-relevantlogic.com ~ http://relevantlogic.com ~ +1 512 784 3178
>
> Ruby/Rails,  REALbasic, PHP programming
> PostgreSQL, MySQL database design and consulting
> Technical writing and training
>
> Read my book, Real OOP with REALbasic: <
> http://relevantlogic.com/oop-book/about-the-oop-book.php
>  >
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby
-~----------~----~----~----~------~----~------~--~---

Reply via email to