Sha256: a2c8830b267f981fea1b374d0a3347841de2a7af1ec06b9b9806f7bb1a3d9108
Contents?: true
Size: 1 KB
Versions: 4
Compression:
Stored size: 1 KB
Contents
module InheritsMigration def self.included(base) base.class_eval do alias_method_chain :create_table , :inherits end end # Generate the association field. def create_table_with_inherits(table_name, options = {}, &block) options[:id] ||= false if options[:inherits] create_table_without_inherits(table_name, options) do |table_defintion| if options[:inherits] association_type = Object.const_get(options[:inherits].to_s.capitalize) association_inst = association_type.send(:new) attr_column = association_inst.column_for_attribute(association_type.primary_key) field_option = {:primary_key => true, :null => false} field_option[:limit] = attr_column.limit if attr_column.limit table_defintion.column "#{options[:inherits]}_id", attr_column.type, field_option end yield table_defintion end end end ActiveRecord::ConnectionAdapters::SchemaStatements::send(:include, InheritsMigration)
Version data entries
4 entries across 4 versions & 1 rubygems