Sha256: edc2aa5996b8c3e3802188c712aaa4c8025e448ae203ee4ef6bdd00b7a6159ab
Contents?: true
Size: 1.18 KB
Versions: 2
Compression:
Stored size: 1.18 KB
Contents
module UsesguidMigrations module ActiveRecordExtensions module ConnectionAdapters module TableDefinition def self.included( base ) base.class_eval do include InstanceMethods attr_accessor :primary_key_name attr_accessor :associative_keys end end module InstanceMethods def guid_primary_key( name ) @primary_key_name = name column( name, :binary, :limit => 22, :null => false ) end def references_with_guid( name, options={} ) name = name.to_s name = "#{name}_id" unless name.end_with?( "_id" ) guid( name, options ) end def guid( name, options={} ) @associative_keys = [] if @associative_keys.nil? options.merge!( :limit => 22 ) options.merge!( :null => false ) unless options[:null] == true # make not nullable the default for a guid column as it is likely a foreign key @associative_keys << OpenStruct.new( :name => name, :options => options ) column( name, :binary, options ) end end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems