module Concernz module Booking extend ActiveSupport::Concern included do self.primary_key = 'booking_id' # Booking involves Person belongs_to :person, :foreign_key => :person_id # Booking involves Session belongs_to :session, :foreign_key => :session_id # Booking is involved in Seat Allocation has_many :seat_allocations, :class_name => 'SeatAllocation', :foreign_key => :booking_id, :dependent => :destroy has_many :seats, :through => :seat_allocations validates :number, :presence => true validates :person_id, :presence => true validates :session_id, :presence => true end end end module Concernz module Cinema extend ActiveSupport::Concern included do self.primary_key = 'cinema_id' # Cinema contains Row and Row contains Seat has_many :seats_via_row, :class_name => 'Seat', :foreign_key => :row_cinema_id, :dependent => :destroy has_many :row_nrs, :through => :seats_via_row # Cinema is involved in Session has_many :sessions, :class_name => 'Session', :foreign_key => :cinema_id, :dependent => :destroy end end end module Concernz module Film extend ActiveSupport::Concern included do self.primary_key = 'film_id' # Film is involved in Session has_many :sessions, :class_name => 'Session', :foreign_key => :film_id, :dependent => :destroy end end end module Concernz module Person extend ActiveSupport::Concern included do self.primary_key = 'person_id' # Person is involved in Booking has_many :bookings, :class_name => 'Booking', :foreign_key => :person_id, :dependent => :destroy validates :login_name, :presence => true end end end module Concernz module Seat extend ActiveSupport::Concern included do self.primary_key = 'seat_id' # Seat is in Row and Row is in Cinema belongs_to :cinema_via_row, :class_name => 'Cinema', :foreign_key => :row_cinema_id # Seat is involved in Seat Allocation has_many :seat_allocations, :class_name => 'SeatAllocation', :foreign_key => :allocated_seat_id, :dependent => :destroy has_many :bookings, :through => :seat_allocations validates :row_cinema_id, :presence => true validates :row_nr, :presence => true validates :seat_number, :presence => true end end end module Concernz module SeatAllocation extend ActiveSupport::Concern included do # Seat Allocation involves Booking belongs_to :booking, :foreign_key => :booking_id # Seat Allocation involves Seat belongs_to :allocated_seat, :class_name => 'Seat', :foreign_key => :allocated_seat_id validates :booking_id, :presence => true validates :allocated_seat_id, :presence => true end end end module Concernz module Session extend ActiveSupport::Concern included do self.primary_key = 'session_id' # Session involves Cinema belongs_to :cinema, :foreign_key => :cinema_id # Session involves Film belongs_to :film, :foreign_key => :film_id # Session is involved in Booking has_many :bookings, :class_name => 'Booking', :foreign_key => :session_id, :dependent => :destroy validates :cinema_id, :presence => true validates :date_time_value, :presence => true validates :film_id, :presence => true end end end