Skip to content

Instantly share code, notes, and snippets.

@davejlong
Last active October 4, 2015 10:35
Show Gist options
  • Save davejlong/f353ac585db96b63939d to your computer and use it in GitHub Desktop.
Save davejlong/f353ac585db96b63939d to your computer and use it in GitHub Desktop.
Representing relationships in Lotus::Model
class Conference
include Lotus::Entity
attributes :title, :call_code, :technician_id
# Are the following 2 methods correct for representing the relationship to Technician
def technician
@technician ||= TechnicianRepository.find @technician_id
end
def technician=(technician)
@technician = technician
@technician_id = technician.id
end
def call_code
@call_code ||= rand 1000...9999
end
end
class ConferenceRepository
include Lotus::Repository
end
collection :conferences do
entity Conference
repository ConferenceRepository
attribute :id, Integer
attribute :title, String
attribute :call_code, Integer
attribute :technician_id, Integer
end
collection :technicians do
entity Technician
repository TechnicianRepository
attribute :id, Integer
attribute :name, String
attribute :email, String
end
class Technician
include Lotus::Entity
attributes :name, :email
end
class TechnicianRepository
include Lotus::Repository
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment