Skip to content

Instantly share code, notes, and snippets.

@arbales
Created December 22, 2009 03:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save arbales/261484 to your computer and use it in GitHub Desktop.
Save arbales/261484 to your computer and use it in GitHub Desktop.
class Table
include DataMapper::Resource
property :id, Serial
property :name, String
# Relationship to the join table.
has n, :tableBookings
# Defines that Table has bookings in :tableBookings on the :booking named relationship. (a)
has n, :bookings, :through => :tableBookings, :via => :booking
end
class Booking
include DataMapper::Resource
property :id, Serial
has n, :tableBookings
# Defines that Booking has tables in :tableBookings on the :booking relationship. (b)
has n, :tables, :through => :tableBookings, :via => :table
belongs_to :employee
belongs_to :customer
end
class TableBooking
include DataMapper::Resource
property :serial, Serial
property :table_id, Integer, :min => 1 # (a)
property :booking_id, Integer, :min => 1 # (b)
belongs_to :table # (a)
belongs_to :booking # (b)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment