Skip to content

Commit

Permalink
Use Sequel::Model subclass as base class for models
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyevans committed Jun 29, 2016
1 parent 990329d commit 705d8e6
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ module Giftsmas
BCRYPT_COST = BCrypt::Engine::MIN_COST
end

Sequel::Model.plugin :prepared_statements
Sequel::Model.plugin :prepared_statements_associations
Model = Class.new(Sequel::Model)
Model.plugin :prepared_statements
Model.plugin :prepared_statements_associations

%w'user event person gift'.each{|x| require ::File.expand_path("../models/#{x}", __FILE__)}
end
2 changes: 1 addition & 1 deletion models/event.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Giftsmas
class Event < Sequel::Model(DB)
class Event < Model
many_to_one :user
one_to_many :gifts, :eager=>[:receivers, :senders], :order=>:id
many_to_many :senders, :class=>"Giftsmas::Person", :join_table=>:event_senders, :right_key=>:person_id, :order=>:name
Expand Down
2 changes: 1 addition & 1 deletion models/gift.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Giftsmas
class Gift < Sequel::Model(DB)
class Gift < Model
many_to_many :senders, :class=>"Giftsmas::Person", :join_table=>:gift_senders, :right_key=>:person_id, :order=>:name
many_to_many :receivers, :class=>"Giftsmas::Person", :join_table=>:gift_receivers, :right_key=>:person_id, :order=>:name
many_to_one :event
Expand Down
2 changes: 1 addition & 1 deletion models/person.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Giftsmas
class Person < Sequel::Model(DB)
class Person < Model
many_to_many :sender_events, :class=>"Giftsmas::Event", :join_table=>:event_senders, :right_key=>:event_id, :order=>:name
many_to_many :receiver_events, :class=>"Giftsmas::Event", :join_table=>:event_receivers, :right_key=>:event_id, :order=>:name
many_to_many :gifts_sent, :class=>"Giftsmas::Gift", :join_table=>:gift_senders, :right_key=>:gift_id, :order=>:inserted_at
Expand Down
2 changes: 1 addition & 1 deletion models/user.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Giftsmas
class User < Sequel::Model(DB)
class User < Model
one_to_many :events, :order=>:name

def password=(new_password)
Expand Down

0 comments on commit 705d8e6

Please sign in to comment.