Module: UsesguidMigrations::ActiveRecordExtensions::ConnectionAdapters::TableDefinition::InstanceMethods

Defined in:
lib/usesguid_migrations/active_record_extensions/connection_adapters/table_definition.rb

Instance Method Summary collapse

Instance Method Details

#guid(name, options = {}) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/usesguid_migrations/active_record_extensions/connection_adapters/table_definition.rb', line 26

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

#guid_primary_key(name) ⇒ Object



15
16
17
18
# File 'lib/usesguid_migrations/active_record_extensions/connection_adapters/table_definition.rb', line 15

def guid_primary_key( name )
  @primary_key_name = name
  column( name, :binary, :limit => 22, :null => false )
end

#references_with_guid(name, options = {}) ⇒ Object



20
21
22
23
24
# File 'lib/usesguid_migrations/active_record_extensions/connection_adapters/table_definition.rb', line 20

def references_with_guid( name, options={} )
  name = name.to_s
  name = "#{name}_id" unless name.end_with?( "_id" )
  guid( name, options )
end