i’m a newbie working on my first commerical rails project. i’ve got some
models that i’m stuck with, not sure whether i need to redesign the
schema’s or stick to my earlier design as i can quite get what i want
from the way i’ve implemented my associations.
Basically i want to access the bookings for a room. the room has_many
beds, bed has_many booking_items and a booking_item belongs_to a
So how can i get the bookings for a bed???
I know i can do a find_by_sql but then i cant use :include and to be
honest this seems simple enough and i’d rather stick to the rails way so
to speak and use the association proxies etc.
Additionally i want to get the rooms for a booking, but i think that is
the same problem.
I had looked at the nested has many plugin but i managed not to get that
Any help would be really appreciated as i think i’m going to add a
Room_Id field to the bookingItem which would mean i could use the
standard rails associations.
rails version: 2.1.1
class Bed < ActiveRecord::Base
class BookingItem < ActiveRecord::Base
class Booking < ActiveRecord::Base
has_many :booking_items, :dependent => :destroy
has_many :beds, :through => :booking_items
has_many :rooms, :through => :beds # THIS IS NOT WORKING
class Room < ActiveRecord::Base
has_many :booking_items, :through => :beds
has_many :bookings, :through => :booking_items, :source =>
# THIS IS NOT WORKING, I TRIED TO USE NESTED HAS MANY HERE.