-
-
Save jeremyevans/1294055 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Sequel | |
module Plugins | |
module OracleSequence | |
def self.configure(model, seq=nil) | |
model.sequence = seq || model.dataset.opts[:sequence] | |
model.dataset = model.dataset.sequence(nil) if model.dataset.opts[:sequence] | |
end | |
module ClassMethods | |
attr_accessor :sequence | |
end | |
module InstanceMethods | |
def before_create | |
seq_name = model.sequence | |
unless self.class.simple_pk.nil? or seq_name.nil? | |
self.send("#{self.primary_key.to_s}=", db.fetch("SELECT #{seq_name}.NEXTVAL FROM DUAL").all.first.values.first.to_i) | |
end | |
super | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment