activerecord 3.2.22.4 → 4.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of activerecord might be problematic. Click here for more details.
- checksums.yaml +4 -4
 - data/CHANGELOG.md +2799 -617
 - data/MIT-LICENSE +1 -1
 - data/README.rdoc +23 -32
 - data/examples/performance.rb +1 -1
 - data/lib/active_record/aggregations.rb +40 -34
 - data/lib/active_record/association_relation.rb +22 -0
 - data/lib/active_record/associations/alias_tracker.rb +4 -2
 - data/lib/active_record/associations/association.rb +60 -46
 - data/lib/active_record/associations/association_scope.rb +46 -40
 - data/lib/active_record/associations/belongs_to_association.rb +17 -4
 - data/lib/active_record/associations/belongs_to_polymorphic_association.rb +1 -1
 - data/lib/active_record/associations/builder/association.rb +81 -28
 - data/lib/active_record/associations/builder/belongs_to.rb +73 -56
 - data/lib/active_record/associations/builder/collection_association.rb +54 -40
 - data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +23 -41
 - data/lib/active_record/associations/builder/has_many.rb +8 -64
 - data/lib/active_record/associations/builder/has_one.rb +13 -50
 - data/lib/active_record/associations/builder/singular_association.rb +13 -13
 - data/lib/active_record/associations/collection_association.rb +130 -96
 - data/lib/active_record/associations/collection_proxy.rb +916 -63
 - data/lib/active_record/associations/has_and_belongs_to_many_association.rb +15 -13
 - data/lib/active_record/associations/has_many_association.rb +35 -8
 - data/lib/active_record/associations/has_many_through_association.rb +37 -17
 - data/lib/active_record/associations/has_one_association.rb +42 -19
 - data/lib/active_record/associations/has_one_through_association.rb +1 -1
 - data/lib/active_record/associations/join_dependency/join_association.rb +39 -22
 - data/lib/active_record/associations/join_dependency/join_base.rb +2 -2
 - data/lib/active_record/associations/join_dependency/join_part.rb +21 -8
 - data/lib/active_record/associations/join_dependency.rb +30 -9
 - data/lib/active_record/associations/join_helper.rb +1 -11
 - data/lib/active_record/associations/preloader/association.rb +29 -33
 - data/lib/active_record/associations/preloader/collection_association.rb +1 -1
 - data/lib/active_record/associations/preloader/has_and_belongs_to_many.rb +2 -2
 - data/lib/active_record/associations/preloader/has_many_through.rb +6 -2
 - data/lib/active_record/associations/preloader/has_one.rb +1 -1
 - data/lib/active_record/associations/preloader/through_association.rb +13 -17
 - data/lib/active_record/associations/preloader.rb +20 -43
 - data/lib/active_record/associations/singular_association.rb +11 -11
 - data/lib/active_record/associations/through_association.rb +3 -3
 - data/lib/active_record/associations.rb +223 -282
 - data/lib/active_record/attribute_assignment.rb +134 -154
 - data/lib/active_record/attribute_methods/before_type_cast.rb +44 -5
 - data/lib/active_record/attribute_methods/dirty.rb +36 -29
 - data/lib/active_record/attribute_methods/primary_key.rb +45 -31
 - data/lib/active_record/attribute_methods/query.rb +5 -4
 - data/lib/active_record/attribute_methods/read.rb +67 -90
 - data/lib/active_record/attribute_methods/serialization.rb +133 -70
 - data/lib/active_record/attribute_methods/time_zone_conversion.rb +51 -45
 - data/lib/active_record/attribute_methods/write.rb +34 -39
 - data/lib/active_record/attribute_methods.rb +268 -108
 - data/lib/active_record/autosave_association.rb +80 -73
 - data/lib/active_record/base.rb +54 -451
 - data/lib/active_record/callbacks.rb +60 -22
 - data/lib/active_record/coders/yaml_column.rb +18 -21
 - data/lib/active_record/connection_adapters/abstract/connection_pool.rb +347 -197
 - data/lib/active_record/connection_adapters/abstract/database_limits.rb +9 -0
 - data/lib/active_record/connection_adapters/abstract/database_statements.rb +146 -138
 - data/lib/active_record/connection_adapters/abstract/query_cache.rb +25 -19
 - data/lib/active_record/connection_adapters/abstract/quoting.rb +19 -3
 - data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +151 -142
 - data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +70 -0
 - data/lib/active_record/connection_adapters/abstract/schema_statements.rb +499 -217
 - data/lib/active_record/connection_adapters/abstract/transaction.rb +208 -0
 - data/lib/active_record/connection_adapters/abstract_adapter.rb +209 -44
 - data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +169 -61
 - data/lib/active_record/connection_adapters/column.rb +67 -36
 - data/lib/active_record/connection_adapters/connection_specification.rb +96 -0
 - data/lib/active_record/connection_adapters/mysql2_adapter.rb +28 -29
 - data/lib/active_record/connection_adapters/mysql_adapter.rb +200 -73
 - data/lib/active_record/connection_adapters/postgresql/array_parser.rb +98 -0
 - data/lib/active_record/connection_adapters/postgresql/cast.rb +160 -0
 - data/lib/active_record/connection_adapters/postgresql/database_statements.rb +240 -0
 - data/lib/active_record/connection_adapters/postgresql/oid.rb +374 -0
 - data/lib/active_record/connection_adapters/postgresql/quoting.rb +183 -0
 - data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +30 -0
 - data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +508 -0
 - data/lib/active_record/connection_adapters/postgresql_adapter.rb +544 -899
 - data/lib/active_record/connection_adapters/schema_cache.rb +76 -16
 - data/lib/active_record/connection_adapters/sqlite3_adapter.rb +595 -16
 - data/lib/active_record/connection_handling.rb +98 -0
 - data/lib/active_record/core.rb +472 -0
 - data/lib/active_record/counter_cache.rb +107 -108
 - data/lib/active_record/dynamic_matchers.rb +115 -63
 - data/lib/active_record/errors.rb +36 -18
 - data/lib/active_record/explain.rb +15 -63
 - data/lib/active_record/explain_registry.rb +30 -0
 - data/lib/active_record/explain_subscriber.rb +8 -4
 - data/lib/active_record/fixture_set/file.rb +55 -0
 - data/lib/active_record/fixtures.rb +159 -155
 - data/lib/active_record/inheritance.rb +93 -59
 - data/lib/active_record/integration.rb +8 -8
 - data/lib/active_record/locale/en.yml +8 -1
 - data/lib/active_record/locking/optimistic.rb +39 -43
 - data/lib/active_record/locking/pessimistic.rb +4 -4
 - data/lib/active_record/log_subscriber.rb +19 -9
 - data/lib/active_record/migration/command_recorder.rb +102 -33
 - data/lib/active_record/migration/join_table.rb +15 -0
 - data/lib/active_record/migration.rb +411 -173
 - data/lib/active_record/model_schema.rb +81 -94
 - data/lib/active_record/nested_attributes.rb +173 -131
 - data/lib/active_record/null_relation.rb +67 -0
 - data/lib/active_record/persistence.rb +254 -106
 - data/lib/active_record/query_cache.rb +18 -36
 - data/lib/active_record/querying.rb +19 -15
 - data/lib/active_record/railtie.rb +113 -38
 - data/lib/active_record/railties/console_sandbox.rb +3 -4
 - data/lib/active_record/railties/controller_runtime.rb +4 -3
 - data/lib/active_record/railties/databases.rake +115 -368
 - data/lib/active_record/railties/jdbcmysql_error.rb +1 -1
 - data/lib/active_record/readonly_attributes.rb +7 -3
 - data/lib/active_record/reflection.rb +110 -61
 - data/lib/active_record/relation/batches.rb +29 -29
 - data/lib/active_record/relation/calculations.rb +155 -125
 - data/lib/active_record/relation/delegation.rb +94 -18
 - data/lib/active_record/relation/finder_methods.rb +151 -203
 - data/lib/active_record/relation/merger.rb +188 -0
 - data/lib/active_record/relation/predicate_builder.rb +85 -42
 - data/lib/active_record/relation/query_methods.rb +793 -146
 - data/lib/active_record/relation/spawn_methods.rb +43 -150
 - data/lib/active_record/relation.rb +293 -173
 - data/lib/active_record/result.rb +48 -7
 - data/lib/active_record/runtime_registry.rb +17 -0
 - data/lib/active_record/sanitization.rb +41 -54
 - data/lib/active_record/schema.rb +19 -12
 - data/lib/active_record/schema_dumper.rb +41 -41
 - data/lib/active_record/schema_migration.rb +46 -0
 - data/lib/active_record/scoping/default.rb +56 -52
 - data/lib/active_record/scoping/named.rb +78 -103
 - data/lib/active_record/scoping.rb +54 -124
 - data/lib/active_record/serialization.rb +6 -2
 - data/lib/active_record/serializers/xml_serializer.rb +9 -15
 - data/lib/active_record/statement_cache.rb +26 -0
 - data/lib/active_record/store.rb +131 -15
 - data/lib/active_record/tasks/database_tasks.rb +204 -0
 - data/lib/active_record/tasks/firebird_database_tasks.rb +56 -0
 - data/lib/active_record/tasks/mysql_database_tasks.rb +144 -0
 - data/lib/active_record/tasks/oracle_database_tasks.rb +45 -0
 - data/lib/active_record/tasks/postgresql_database_tasks.rb +90 -0
 - data/lib/active_record/tasks/sqlite_database_tasks.rb +51 -0
 - data/lib/active_record/tasks/sqlserver_database_tasks.rb +48 -0
 - data/lib/active_record/test_case.rb +67 -38
 - data/lib/active_record/timestamp.rb +16 -11
 - data/lib/active_record/transactions.rb +73 -51
 - data/lib/active_record/validations/associated.rb +19 -13
 - data/lib/active_record/validations/presence.rb +65 -0
 - data/lib/active_record/validations/uniqueness.rb +110 -57
 - data/lib/active_record/validations.rb +18 -17
 - data/lib/active_record/version.rb +7 -6
 - data/lib/active_record.rb +63 -45
 - data/lib/rails/generators/active_record/migration/migration_generator.rb +45 -8
 - data/lib/rails/generators/active_record/{model/templates/migration.rb → migration/templates/create_table_migration.rb} +4 -0
 - data/lib/rails/generators/active_record/migration/templates/migration.rb +20 -15
 - data/lib/rails/generators/active_record/model/model_generator.rb +5 -4
 - data/lib/rails/generators/active_record/model/templates/model.rb +4 -6
 - data/lib/rails/generators/active_record/model/templates/module.rb +1 -1
 - data/lib/rails/generators/active_record.rb +3 -5
 - metadata +43 -29
 - data/examples/associations.png +0 -0
 - data/lib/active_record/attribute_methods/deprecated_underscore_read.rb +0 -32
 - data/lib/active_record/connection_adapters/abstract/connection_specification.rb +0 -191
 - data/lib/active_record/connection_adapters/sqlite_adapter.rb +0 -583
 - data/lib/active_record/dynamic_finder_match.rb +0 -68
 - data/lib/active_record/dynamic_scope_match.rb +0 -23
 - data/lib/active_record/fixtures/file.rb +0 -65
 - data/lib/active_record/identity_map.rb +0 -162
 - data/lib/active_record/observer.rb +0 -121
 - data/lib/active_record/session_store.rb +0 -360
 - data/lib/rails/generators/active_record/migration.rb +0 -15
 - data/lib/rails/generators/active_record/observer/observer_generator.rb +0 -15
 - data/lib/rails/generators/active_record/observer/templates/observer.rb +0 -4
 - data/lib/rails/generators/active_record/session_migration/session_migration_generator.rb +0 -25
 - data/lib/rails/generators/active_record/session_migration/templates/migration.rb +0 -12
 
| 
         @@ -8,66 +8,125 @@ module ActiveRecord 
     | 
|
| 
       8 
8 
     | 
    
         
             
                # * add_index
         
     | 
| 
       9 
9 
     | 
    
         
             
                # * add_timestamps
         
     | 
| 
       10 
10 
     | 
    
         
             
                # * create_table
         
     | 
| 
      
 11 
     | 
    
         
            +
                # * create_join_table
         
     | 
| 
       11 
12 
     | 
    
         
             
                # * remove_timestamps
         
     | 
| 
       12 
13 
     | 
    
         
             
                # * rename_column
         
     | 
| 
       13 
14 
     | 
    
         
             
                # * rename_index
         
     | 
| 
       14 
15 
     | 
    
         
             
                # * rename_table
         
     | 
| 
       15 
16 
     | 
    
         
             
                class CommandRecorder
         
     | 
| 
       16 
     | 
    
         
            -
                   
     | 
| 
      
 17 
     | 
    
         
            +
                  include JoinTable
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                  attr_accessor :commands, :delegate, :reverting
         
     | 
| 
       17 
20 
     | 
    
         | 
| 
       18 
21 
     | 
    
         
             
                  def initialize(delegate = nil)
         
     | 
| 
       19 
22 
     | 
    
         
             
                    @commands = []
         
     | 
| 
       20 
23 
     | 
    
         
             
                    @delegate = delegate
         
     | 
| 
      
 24 
     | 
    
         
            +
                    @reverting = false
         
     | 
| 
      
 25 
     | 
    
         
            +
                  end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                  # While executing the given block, the recorded will be in reverting mode.
         
     | 
| 
      
 28 
     | 
    
         
            +
                  # All commands recorded will end up being recorded reverted
         
     | 
| 
      
 29 
     | 
    
         
            +
                  # and in reverse order.
         
     | 
| 
      
 30 
     | 
    
         
            +
                  # For example:
         
     | 
| 
      
 31 
     | 
    
         
            +
                  #
         
     | 
| 
      
 32 
     | 
    
         
            +
                  #   recorder.revert{ recorder.record(:rename_table, [:old, :new]) }
         
     | 
| 
      
 33 
     | 
    
         
            +
                  #   # same effect as recorder.record(:rename_table, [:new, :old])
         
     | 
| 
      
 34 
     | 
    
         
            +
                  def revert
         
     | 
| 
      
 35 
     | 
    
         
            +
                    @reverting = !@reverting
         
     | 
| 
      
 36 
     | 
    
         
            +
                    previous = @commands
         
     | 
| 
      
 37 
     | 
    
         
            +
                    @commands = []
         
     | 
| 
      
 38 
     | 
    
         
            +
                    yield
         
     | 
| 
      
 39 
     | 
    
         
            +
                  ensure
         
     | 
| 
      
 40 
     | 
    
         
            +
                    @commands = previous.concat(@commands.reverse)
         
     | 
| 
      
 41 
     | 
    
         
            +
                    @reverting = !@reverting
         
     | 
| 
       21 
42 
     | 
    
         
             
                  end
         
     | 
| 
       22 
43 
     | 
    
         | 
| 
       23 
44 
     | 
    
         
             
                  # record +command+. +command+ should be a method name and arguments.
         
     | 
| 
       24 
45 
     | 
    
         
             
                  # For example:
         
     | 
| 
       25 
46 
     | 
    
         
             
                  #
         
     | 
| 
       26 
47 
     | 
    
         
             
                  #   recorder.record(:method_name, [:arg1, :arg2])
         
     | 
| 
       27 
     | 
    
         
            -
                  def record(*command)
         
     | 
| 
       28 
     | 
    
         
            -
                    @ 
     | 
| 
      
 48 
     | 
    
         
            +
                  def record(*command, &block)
         
     | 
| 
      
 49 
     | 
    
         
            +
                    if @reverting
         
     | 
| 
      
 50 
     | 
    
         
            +
                      @commands << inverse_of(*command, &block)
         
     | 
| 
      
 51 
     | 
    
         
            +
                    else
         
     | 
| 
      
 52 
     | 
    
         
            +
                      @commands << (command << block)
         
     | 
| 
      
 53 
     | 
    
         
            +
                    end
         
     | 
| 
       29 
54 
     | 
    
         
             
                  end
         
     | 
| 
       30 
55 
     | 
    
         | 
| 
       31 
     | 
    
         
            -
                  # Returns  
     | 
| 
       32 
     | 
    
         
            -
                  # commands stored in +commands+. For example:
         
     | 
| 
      
 56 
     | 
    
         
            +
                  # Returns the inverse of the given command. For example:
         
     | 
| 
       33 
57 
     | 
    
         
             
                  #
         
     | 
| 
       34 
     | 
    
         
            -
                  #   recorder. 
     | 
| 
       35 
     | 
    
         
            -
                  #    
     | 
| 
      
 58 
     | 
    
         
            +
                  #   recorder.inverse_of(:rename_table, [:old, :new])
         
     | 
| 
      
 59 
     | 
    
         
            +
                  #   # => [:rename_table, [:new, :old]]
         
     | 
| 
       36 
60 
     | 
    
         
             
                  #
         
     | 
| 
       37 
61 
     | 
    
         
             
                  # This method will raise an +IrreversibleMigration+ exception if it cannot
         
     | 
| 
       38 
     | 
    
         
            -
                  # invert the + 
     | 
| 
       39 
     | 
    
         
            -
                  def  
     | 
| 
       40 
     | 
    
         
            -
                     
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
                      send(method, args)
         
     | 
| 
       44 
     | 
    
         
            -
                    }
         
     | 
| 
      
 62 
     | 
    
         
            +
                  # invert the +command+.
         
     | 
| 
      
 63 
     | 
    
         
            +
                  def inverse_of(command, args, &block)
         
     | 
| 
      
 64 
     | 
    
         
            +
                    method = :"invert_#{command}"
         
     | 
| 
      
 65 
     | 
    
         
            +
                    raise IrreversibleMigration unless respond_to?(method, true)
         
     | 
| 
      
 66 
     | 
    
         
            +
                    send(method, args, &block)
         
     | 
| 
       45 
67 
     | 
    
         
             
                  end
         
     | 
| 
       46 
68 
     | 
    
         | 
| 
       47 
69 
     | 
    
         
             
                  def respond_to?(*args) # :nodoc:
         
     | 
| 
       48 
70 
     | 
    
         
             
                    super || delegate.respond_to?(*args)
         
     | 
| 
       49 
71 
     | 
    
         
             
                  end
         
     | 
| 
       50 
72 
     | 
    
         | 
| 
       51 
     | 
    
         
            -
                  [:create_table, : 
     | 
| 
      
 73 
     | 
    
         
            +
                  [:create_table, :create_join_table, :rename_table, :add_column, :remove_column,
         
     | 
| 
      
 74 
     | 
    
         
            +
                    :rename_index, :rename_column, :add_index, :remove_index, :add_timestamps, :remove_timestamps,
         
     | 
| 
      
 75 
     | 
    
         
            +
                    :change_column_default, :add_reference, :remove_reference, :transaction,
         
     | 
| 
      
 76 
     | 
    
         
            +
                    :drop_join_table, :drop_table, :execute_block,
         
     | 
| 
      
 77 
     | 
    
         
            +
                    :change_column, :execute, :remove_columns, # irreversible methods need to be here too
         
     | 
| 
      
 78 
     | 
    
         
            +
                  ].each do |method|
         
     | 
| 
       52 
79 
     | 
    
         
             
                    class_eval <<-EOV, __FILE__, __LINE__ + 1
         
     | 
| 
       53 
     | 
    
         
            -
                      def #{method}(*args)          # def create_table(*args)
         
     | 
| 
       54 
     | 
    
         
            -
                        record(:"#{method}", args)  #   record(:create_table, args)
         
     | 
| 
       55 
     | 
    
         
            -
                      end 
     | 
| 
      
 80 
     | 
    
         
            +
                      def #{method}(*args, &block)          # def create_table(*args, &block)
         
     | 
| 
      
 81 
     | 
    
         
            +
                        record(:"#{method}", args, &block)  #   record(:create_table, args, &block)
         
     | 
| 
      
 82 
     | 
    
         
            +
                      end                                   # end
         
     | 
| 
       56 
83 
     | 
    
         
             
                    EOV
         
     | 
| 
       57 
84 
     | 
    
         
             
                  end
         
     | 
| 
      
 85 
     | 
    
         
            +
                  alias :add_belongs_to :add_reference
         
     | 
| 
      
 86 
     | 
    
         
            +
                  alias :remove_belongs_to :remove_reference
         
     | 
| 
      
 87 
     | 
    
         
            +
             
     | 
| 
      
 88 
     | 
    
         
            +
                  def change_table(table_name, options = {})
         
     | 
| 
      
 89 
     | 
    
         
            +
                    yield delegate.update_table_definition(table_name, self)
         
     | 
| 
      
 90 
     | 
    
         
            +
                  end
         
     | 
| 
       58 
91 
     | 
    
         | 
| 
       59 
92 
     | 
    
         
             
                  private
         
     | 
| 
       60 
93 
     | 
    
         | 
| 
       61 
     | 
    
         
            -
                   
     | 
| 
       62 
     | 
    
         
            -
                     
     | 
| 
      
 94 
     | 
    
         
            +
                  module StraightReversions
         
     | 
| 
      
 95 
     | 
    
         
            +
                    private
         
     | 
| 
      
 96 
     | 
    
         
            +
                    { transaction:       :transaction,
         
     | 
| 
      
 97 
     | 
    
         
            +
                      execute_block:     :execute_block,
         
     | 
| 
      
 98 
     | 
    
         
            +
                      create_table:      :drop_table,
         
     | 
| 
      
 99 
     | 
    
         
            +
                      create_join_table: :drop_join_table,
         
     | 
| 
      
 100 
     | 
    
         
            +
                      add_column:        :remove_column,
         
     | 
| 
      
 101 
     | 
    
         
            +
                      add_timestamps:    :remove_timestamps,
         
     | 
| 
      
 102 
     | 
    
         
            +
                      add_reference:     :remove_reference,
         
     | 
| 
      
 103 
     | 
    
         
            +
                    }.each do |cmd, inv|
         
     | 
| 
      
 104 
     | 
    
         
            +
                      [[inv, cmd], [cmd, inv]].uniq.each do |method, inverse|
         
     | 
| 
      
 105 
     | 
    
         
            +
                        class_eval <<-EOV, __FILE__, __LINE__ + 1
         
     | 
| 
      
 106 
     | 
    
         
            +
                          def invert_#{method}(args, &block)    # def invert_create_table(args, &block)
         
     | 
| 
      
 107 
     | 
    
         
            +
                            [:#{inverse}, args, block]          #   [:drop_table, args, block]
         
     | 
| 
      
 108 
     | 
    
         
            +
                          end                                   # end
         
     | 
| 
      
 109 
     | 
    
         
            +
                        EOV
         
     | 
| 
      
 110 
     | 
    
         
            +
                      end
         
     | 
| 
      
 111 
     | 
    
         
            +
                    end
         
     | 
| 
      
 112 
     | 
    
         
            +
                  end
         
     | 
| 
      
 113 
     | 
    
         
            +
             
     | 
| 
      
 114 
     | 
    
         
            +
                  include StraightReversions
         
     | 
| 
      
 115 
     | 
    
         
            +
             
     | 
| 
      
 116 
     | 
    
         
            +
                  def invert_drop_table(args, &block)
         
     | 
| 
      
 117 
     | 
    
         
            +
                    if args.size == 1 && block == nil
         
     | 
| 
      
 118 
     | 
    
         
            +
                      raise ActiveRecord::IrreversibleMigration, "To avoid mistakes, drop_table is only reversible if given options or a block (can be empty)."
         
     | 
| 
      
 119 
     | 
    
         
            +
                    end
         
     | 
| 
      
 120 
     | 
    
         
            +
                    super
         
     | 
| 
       63 
121 
     | 
    
         
             
                  end
         
     | 
| 
       64 
122 
     | 
    
         | 
| 
       65 
123 
     | 
    
         
             
                  def invert_rename_table(args)
         
     | 
| 
       66 
124 
     | 
    
         
             
                    [:rename_table, args.reverse]
         
     | 
| 
       67 
125 
     | 
    
         
             
                  end
         
     | 
| 
       68 
126 
     | 
    
         | 
| 
       69 
     | 
    
         
            -
                  def  
     | 
| 
       70 
     | 
    
         
            -
                     
     | 
| 
      
 127 
     | 
    
         
            +
                  def invert_remove_column(args)
         
     | 
| 
      
 128 
     | 
    
         
            +
                    raise ActiveRecord::IrreversibleMigration, "remove_column is only reversible if given a type." if args.size <= 2
         
     | 
| 
      
 129 
     | 
    
         
            +
                    super
         
     | 
| 
       71 
130 
     | 
    
         
             
                  end
         
     | 
| 
       72 
131 
     | 
    
         | 
| 
       73 
132 
     | 
    
         
             
                  def invert_rename_index(args)
         
     | 
| 
         @@ -80,26 +139,36 @@ module ActiveRecord 
     | 
|
| 
       80 
139 
     | 
    
         | 
| 
       81 
140 
     | 
    
         
             
                  def invert_add_index(args)
         
     | 
| 
       82 
141 
     | 
    
         
             
                    table, columns, options = *args
         
     | 
| 
       83 
     | 
    
         
            -
                     
     | 
| 
       84 
     | 
    
         
            -
             
     | 
| 
      
 142 
     | 
    
         
            +
                    options ||= {}
         
     | 
| 
      
 143 
     | 
    
         
            +
             
     | 
| 
      
 144 
     | 
    
         
            +
                    index_name = options[:name]
         
     | 
| 
      
 145 
     | 
    
         
            +
                    options_hash = index_name ? { name: index_name } : { column: columns }
         
     | 
| 
      
 146 
     | 
    
         
            +
             
     | 
| 
       85 
147 
     | 
    
         
             
                    [:remove_index, [table, options_hash]]
         
     | 
| 
       86 
148 
     | 
    
         
             
                  end
         
     | 
| 
       87 
149 
     | 
    
         | 
| 
       88 
     | 
    
         
            -
                  def  
     | 
| 
       89 
     | 
    
         
            -
                     
     | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
      
 150 
     | 
    
         
            +
                  def invert_remove_index(args)
         
     | 
| 
      
 151 
     | 
    
         
            +
                    table, options = *args
         
     | 
| 
      
 152 
     | 
    
         
            +
             
     | 
| 
      
 153 
     | 
    
         
            +
                    unless options && options.is_a?(Hash) && options[:column]
         
     | 
| 
      
 154 
     | 
    
         
            +
                      raise ActiveRecord::IrreversibleMigration, "remove_index is only reversible if given a :column option."
         
     | 
| 
      
 155 
     | 
    
         
            +
                    end
         
     | 
| 
       91 
156 
     | 
    
         | 
| 
       92 
     | 
    
         
            -
             
     | 
| 
       93 
     | 
    
         
            -
                    [: 
     | 
| 
      
 157 
     | 
    
         
            +
                    options = options.dup
         
     | 
| 
      
 158 
     | 
    
         
            +
                    [:add_index, [table, options.delete(:column), options]]
         
     | 
| 
       94 
159 
     | 
    
         
             
                  end
         
     | 
| 
       95 
160 
     | 
    
         | 
| 
      
 161 
     | 
    
         
            +
                  alias :invert_add_belongs_to :invert_add_reference
         
     | 
| 
      
 162 
     | 
    
         
            +
                  alias :invert_remove_belongs_to :invert_remove_reference
         
     | 
| 
      
 163 
     | 
    
         
            +
             
     | 
| 
       96 
164 
     | 
    
         
             
                  # Forwards any missing method call to the \target.
         
     | 
| 
       97 
165 
     | 
    
         
             
                  def method_missing(method, *args, &block)
         
     | 
| 
       98 
     | 
    
         
            -
                    @delegate. 
     | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
       100 
     | 
    
         
            -
                     
     | 
| 
      
 166 
     | 
    
         
            +
                    if @delegate.respond_to?(method)
         
     | 
| 
      
 167 
     | 
    
         
            +
                      @delegate.send(method, *args, &block)
         
     | 
| 
      
 168 
     | 
    
         
            +
                    else
         
     | 
| 
      
 169 
     | 
    
         
            +
                      super
         
     | 
| 
      
 170 
     | 
    
         
            +
                    end
         
     | 
| 
       101 
171 
     | 
    
         
             
                  end
         
     | 
| 
       102 
     | 
    
         
            -
             
     | 
| 
       103 
172 
     | 
    
         
             
                end
         
     | 
| 
       104 
173 
     | 
    
         
             
              end
         
     | 
| 
       105 
174 
     | 
    
         
             
            end
         
     | 
| 
         @@ -0,0 +1,15 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module ActiveRecord
         
     | 
| 
      
 2 
     | 
    
         
            +
              class Migration
         
     | 
| 
      
 3 
     | 
    
         
            +
                module JoinTable #:nodoc:
         
     | 
| 
      
 4 
     | 
    
         
            +
                  private
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
                  def find_join_table_name(table_1, table_2, options = {})
         
     | 
| 
      
 7 
     | 
    
         
            +
                    options.delete(:table_name) || join_table_name(table_1, table_2)
         
     | 
| 
      
 8 
     | 
    
         
            +
                  end
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                  def join_table_name(table_1, table_2)
         
     | 
| 
      
 11 
     | 
    
         
            +
                    [table_1.to_s, table_2.to_s].sort.join("_").to_sym
         
     | 
| 
      
 12 
     | 
    
         
            +
                  end
         
     | 
| 
      
 13 
     | 
    
         
            +
                end
         
     | 
| 
      
 14 
     | 
    
         
            +
              end
         
     | 
| 
      
 15 
     | 
    
         
            +
            end
         
     |