activerecord 4.2.0.beta4 → 4.2.0.rc1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activerecord might be problematic. Click here for more details.

Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +107 -34
  3. data/lib/active_record/aggregations.rb +2 -2
  4. data/lib/active_record/associations.rb +1 -1
  5. data/lib/active_record/associations/alias_tracker.rb +3 -12
  6. data/lib/active_record/associations/association_scope.rb +1 -2
  7. data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +2 -2
  8. data/lib/active_record/associations/collection_association.rb +29 -6
  9. data/lib/active_record/associations/has_many_association.rb +1 -1
  10. data/lib/active_record/associations/has_many_through_association.rb +2 -2
  11. data/lib/active_record/associations/join_dependency.rb +1 -1
  12. data/lib/active_record/associations/join_dependency/join_association.rb +1 -1
  13. data/lib/active_record/associations/preloader.rb +1 -0
  14. data/lib/active_record/associations/preloader/association.rb +3 -8
  15. data/lib/active_record/associations/preloader/through_association.rb +1 -0
  16. data/lib/active_record/associations/singular_association.rb +2 -1
  17. data/lib/active_record/attribute_methods.rb +2 -2
  18. data/lib/active_record/attribute_methods/dirty.rb +1 -1
  19. data/lib/active_record/attribute_methods/primary_key.rb +2 -1
  20. data/lib/active_record/attribute_methods/read.rb +13 -5
  21. data/lib/active_record/attribute_methods/time_zone_conversion.rb +1 -1
  22. data/lib/active_record/attribute_set.rb +7 -11
  23. data/lib/active_record/attribute_set/builder.rb +66 -17
  24. data/lib/active_record/attributes.rb +20 -3
  25. data/lib/active_record/connection_adapters/abstract/database_statements.rb +0 -4
  26. data/lib/active_record/connection_adapters/abstract/schema_creation.rb +1 -3
  27. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +25 -24
  28. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +9 -3
  29. data/lib/active_record/connection_adapters/abstract_adapter.rb +9 -7
  30. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +25 -13
  31. data/lib/active_record/connection_adapters/connection_specification.rb +1 -1
  32. data/lib/active_record/connection_adapters/mysql2_adapter.rb +6 -0
  33. data/lib/active_record/connection_adapters/mysql_adapter.rb +6 -2
  34. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +0 -4
  35. data/lib/active_record/connection_adapters/postgresql/quoting.rb +6 -16
  36. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +29 -7
  37. data/lib/active_record/connection_adapters/postgresql/utils.rb +15 -4
  38. data/lib/active_record/connection_adapters/postgresql_adapter.rb +15 -6
  39. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +5 -7
  40. data/lib/active_record/connection_handling.rb +1 -1
  41. data/lib/active_record/core.rb +5 -3
  42. data/lib/active_record/enum.rb +1 -1
  43. data/lib/active_record/errors.rb +21 -0
  44. data/lib/active_record/fixtures.rb +4 -2
  45. data/lib/active_record/gem_version.rb +1 -1
  46. data/lib/active_record/locking/optimistic.rb +1 -1
  47. data/lib/active_record/migration.rb +15 -4
  48. data/lib/active_record/model_schema.rb +8 -4
  49. data/lib/active_record/persistence.rb +5 -5
  50. data/lib/active_record/railtie.rb +0 -2
  51. data/lib/active_record/railties/databases.rake +7 -6
  52. data/lib/active_record/reflection.rb +2 -2
  53. data/lib/active_record/relation.rb +21 -13
  54. data/lib/active_record/relation/calculations.rb +1 -0
  55. data/lib/active_record/relation/finder_methods.rb +8 -5
  56. data/lib/active_record/relation/merger.rb +0 -12
  57. data/lib/active_record/relation/predicate_builder/relation_handler.rb +1 -1
  58. data/lib/active_record/relation/query_methods.rb +30 -18
  59. data/lib/active_record/sanitization.rb +4 -1
  60. data/lib/active_record/schema_dumper.rb +1 -6
  61. data/lib/active_record/scoping/named.rb +1 -1
  62. data/lib/active_record/statement_cache.rb +21 -10
  63. data/lib/active_record/tasks/database_tasks.rb +17 -2
  64. data/lib/active_record/tasks/mysql_database_tasks.rb +1 -0
  65. data/lib/active_record/type.rb +1 -0
  66. data/lib/active_record/type/big_integer.rb +13 -0
  67. data/lib/active_record/type/decimal_without_scale.rb +2 -2
  68. data/lib/active_record/type/hash_lookup_type_map.rb +5 -7
  69. data/lib/active_record/type/integer.rb +29 -1
  70. data/lib/active_record/type/serialized.rb +1 -1
  71. data/lib/active_record/type/string.rb +4 -4
  72. data/lib/active_record/type/type_map.rb +23 -7
  73. data/lib/active_record/validations.rb +4 -3
  74. data/lib/active_record/validations/uniqueness.rb +1 -1
  75. data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb +3 -0
  76. data/lib/rails/generators/active_record/migration/templates/migration.rb +6 -0
  77. metadata +15 -20
@@ -66,7 +66,7 @@ module ActiveRecord
66
66
  # the loaded flag is set to true as well.
67
67
  def count_records
68
68
  count = if has_cached_counter?
69
- owner.read_attribute cached_counter_attribute_name
69
+ owner._read_attribute cached_counter_attribute_name
70
70
  else
71
71
  scope.count
72
72
  end
@@ -20,7 +20,7 @@ module ActiveRecord
20
20
  # SELECT query will be generated by using #length instead.
21
21
  def size
22
22
  if has_cached_counter?
23
- owner.read_attribute cached_counter_attribute_name(reflection)
23
+ owner._read_attribute cached_counter_attribute_name(reflection)
24
24
  elsif loaded?
25
25
  target.size
26
26
  else
@@ -161,7 +161,7 @@ module ActiveRecord
161
161
  if scope.klass.primary_key
162
162
  count = scope.destroy_all.length
163
163
  else
164
- scope.to_a.each do |record|
164
+ scope.each do |record|
165
165
  record._run_destroy_callbacks
166
166
  end
167
167
 
@@ -94,7 +94,7 @@ module ActiveRecord
94
94
  #
95
95
  def initialize(base, associations, joins)
96
96
  @alias_tracker = AliasTracker.create(base.connection, joins)
97
- @alias_tracker.aliased_name_for(base.table_name, base.table_name) # Updates the count for base.table_name to 1
97
+ @alias_tracker.aliased_table_for(base.table_name, base.table_name) # Updates the count for base.table_name to 1
98
98
  tree = self.class.make_tree associations
99
99
  @join_root = JoinBase.new base, build(tree, base)
100
100
  @join_root.children.each { |child| construct_tables! @join_root, child }
@@ -67,7 +67,7 @@ module ActiveRecord
67
67
  value = foreign_klass.base_class.name
68
68
  column = klass.columns_hash[reflection.type.to_s]
69
69
 
70
- substitute = klass.connection.substitute_at(column, bind_values.length)
70
+ substitute = klass.connection.substitute_at(column)
71
71
  bind_values.push [column, value]
72
72
  constraint = constraint.and table[reflection.type].eq substitute
73
73
  end
@@ -178,6 +178,7 @@ module ActiveRecord
178
178
  class NullPreloader
179
179
  def self.new(klass, owners, reflection, preload_scope); self; end
180
180
  def self.run(preloader); end
181
+ def self.preloaded_records; []; end
181
182
  end
182
183
 
183
184
  def preloader_for(reflection, owners, rhs_klass)
@@ -142,14 +142,8 @@ module ActiveRecord
142
142
 
143
143
  scope._select! preload_values[:select] || values[:select] || table[Arel.star]
144
144
  scope.includes! preload_values[:includes] || values[:includes]
145
-
146
- if preload_values.key? :order
147
- scope.order! preload_values[:order]
148
- else
149
- if values.key? :order
150
- scope.order! values[:order]
151
- end
152
- end
145
+ scope.joins! preload_values[:joins] || values[:joins]
146
+ scope.order! preload_values[:order] || values[:order]
153
147
 
154
148
  if preload_values[:readonly] || values[:readonly]
155
149
  scope.readonly!
@@ -159,6 +153,7 @@ module ActiveRecord
159
153
  scope.where!(klass.table_name => { reflection.type => model.base_class.sti_name })
160
154
  end
161
155
 
156
+ scope.unscope_values = Array(values[:unscope])
162
157
  klass.default_scoped.merge(scope)
163
158
  end
164
159
  end
@@ -81,6 +81,7 @@ module ActiveRecord
81
81
  unless reflection_scope.where_values.empty?
82
82
  scope.includes_values = Array(reflection_scope.values[:includes] || options[:source])
83
83
  scope.where_values = reflection_scope.values[:where]
84
+ scope.bind_values = reflection_scope.bind_values
84
85
  end
85
86
 
86
87
  scope.references! reflection_scope.values[:references]
@@ -41,7 +41,8 @@ module ActiveRecord
41
41
  def get_records
42
42
  if reflection.scope_chain.any?(&:any?) ||
43
43
  scope.eager_loading? ||
44
- klass.current_scope
44
+ klass.current_scope ||
45
+ klass.default_scopes.any?
45
46
 
46
47
  return scope.limit(1).to_a
47
48
  end
@@ -332,7 +332,7 @@ module ActiveRecord
332
332
  # task.attribute_present?(:title) # => true
333
333
  # task.attribute_present?(:is_done) # => true
334
334
  def attribute_present?(attribute)
335
- value = read_attribute(attribute)
335
+ value = _read_attribute(attribute)
336
336
  !value.nil? && !(value.respond_to?(:empty?) && value.empty?)
337
337
  end
338
338
 
@@ -433,7 +433,7 @@ module ActiveRecord
433
433
  end
434
434
 
435
435
  def typecasted_attribute_value(name)
436
- read_attribute(name)
436
+ _read_attribute(name)
437
437
  end
438
438
  end
439
439
  end
@@ -110,7 +110,7 @@ module ActiveRecord
110
110
  if attribute_changed?(attr)
111
111
  changed_attributes[attr]
112
112
  else
113
- clone_attribute_value(:read_attribute, attr)
113
+ clone_attribute_value(:_read_attribute, attr)
114
114
  end
115
115
  end
116
116
 
@@ -17,7 +17,7 @@ module ActiveRecord
17
17
  def id
18
18
  if pk = self.class.primary_key
19
19
  sync_with_transaction_state
20
- read_attribute(pk)
20
+ _read_attribute(pk)
21
21
  end
22
22
  end
23
23
 
@@ -120,6 +120,7 @@ module ActiveRecord
120
120
  def primary_key=(value)
121
121
  @primary_key = value && value.to_s
122
122
  @quoted_primary_key = nil
123
+ @attributes_builder = nil
123
124
  end
124
125
  end
125
126
  end
@@ -27,7 +27,7 @@ module ActiveRecord
27
27
  <<-EOMETHOD
28
28
  def #{method_name}
29
29
  name = ::ActiveRecord::AttributeMethods::AttrNames::ATTR_#{const_name}
30
- read_attribute(name) { |n| missing_attribute(n, caller) }
30
+ _read_attribute(name) { |n| missing_attribute(n, caller) }
31
31
  end
32
32
  EOMETHOD
33
33
  end
@@ -64,7 +64,7 @@ module ActiveRecord
64
64
  generated_attribute_methods.module_eval <<-STR, __FILE__, __LINE__ + 1
65
65
  def #{temp_method}
66
66
  name = ::ActiveRecord::AttributeMethods::AttrNames::ATTR_#{safe_name}
67
- read_attribute(name) { |n| missing_attribute(n, caller) }
67
+ _read_attribute(name) { |n| missing_attribute(n, caller) }
68
68
  end
69
69
  STR
70
70
 
@@ -76,19 +76,27 @@ module ActiveRecord
76
76
  end
77
77
  end
78
78
 
79
+ ID = 'id'.freeze
80
+
79
81
  # Returns the value of the attribute identified by <tt>attr_name</tt> after
80
82
  # it has been typecast (for example, "2004-12-12" in a date column is cast
81
83
  # to a date object, like Date.new(2004, 12, 12)).
82
84
  def read_attribute(attr_name, &block)
83
85
  name = attr_name.to_s
84
- name = self.class.primary_key if name == 'id'
85
- @attributes.fetch_value(name, &block)
86
+ name = self.class.primary_key if name == ID
87
+ _read_attribute(name, &block)
88
+ end
89
+
90
+ # This method exists to avoid the expensive primary_key check internally, without
91
+ # breaking compatibility with the read_attribute API
92
+ def _read_attribute(attr_name) # :nodoc:
93
+ @attributes.fetch_value(attr_name.to_s) { |n| yield n if block_given? }
86
94
  end
87
95
 
88
96
  private
89
97
 
90
98
  def attribute(attribute_name)
91
- read_attribute(attribute_name)
99
+ _read_attribute(attribute_name)
92
100
  end
93
101
  end
94
102
  end
@@ -1,7 +1,7 @@
1
1
  module ActiveRecord
2
2
  module AttributeMethods
3
3
  module TimeZoneConversion
4
- class TimeZoneConverter < SimpleDelegator # :nodoc:
4
+ class TimeZoneConverter < DelegateClass(Type::Value) # :nodoc:
5
5
  include Type::Decorator
6
6
 
7
7
  def type_cast_from_database(value)
@@ -2,8 +2,6 @@ require 'active_record/attribute_set/builder'
2
2
 
3
3
  module ActiveRecord
4
4
  class AttributeSet # :nodoc:
5
- delegate :keys, to: :initialized_attributes
6
-
7
5
  def initialize(attributes)
8
6
  @attributes = attributes
9
7
  end
@@ -25,8 +23,12 @@ module ActiveRecord
25
23
  attributes.key?(name) && self[name].initialized?
26
24
  end
27
25
 
28
- def fetch_value(name, &block)
29
- self[name].value(&block)
26
+ def keys
27
+ attributes.initialized_keys
28
+ end
29
+
30
+ def fetch_value(name)
31
+ self[name].value { |n| yield n if block_given? }
30
32
  end
31
33
 
32
34
  def write_from_database(name, value)
@@ -43,7 +45,7 @@ module ActiveRecord
43
45
  end
44
46
 
45
47
  def initialize_dup(_)
46
- @attributes = attributes.transform_values(&:dup)
48
+ @attributes = attributes.dup
47
49
  super
48
50
  end
49
51
 
@@ -58,12 +60,6 @@ module ActiveRecord
58
60
  end
59
61
  end
60
62
 
61
- def ensure_initialized(key)
62
- unless self[key].initialized?
63
- write_from_database(key, nil)
64
- end
65
- end
66
-
67
63
  protected
68
64
 
69
65
  attr_reader :attributes
@@ -1,35 +1,84 @@
1
1
  module ActiveRecord
2
2
  class AttributeSet # :nodoc:
3
3
  class Builder # :nodoc:
4
- attr_reader :types
4
+ attr_reader :types, :always_initialized
5
5
 
6
- def initialize(types)
6
+ def initialize(types, always_initialized = nil)
7
7
  @types = types
8
+ @always_initialized = always_initialized
8
9
  end
9
10
 
10
11
  def build_from_database(values = {}, additional_types = {})
11
- attributes = build_attributes_from_values(values, additional_types)
12
- add_uninitialized_attributes(attributes)
12
+ if always_initialized && !values.key?(always_initialized)
13
+ values[always_initialized] = nil
14
+ end
15
+
16
+ attributes = LazyAttributeHash.new(types, values, additional_types)
13
17
  AttributeSet.new(attributes)
14
18
  end
19
+ end
20
+ end
15
21
 
16
- private
22
+ class LazyAttributeHash # :nodoc:
23
+ delegate :select, :transform_values, to: :materialize
17
24
 
18
- def build_attributes_from_values(values, additional_types)
19
- values.each_with_object({}) do |(name, value), hash|
20
- type = additional_types.fetch(name, types[name])
21
- hash[name] = Attribute.from_database(name, value, type)
22
- end
25
+ def initialize(types, values, additional_types)
26
+ @types = types
27
+ @values = values
28
+ @additional_types = additional_types
29
+ @materialized = false
30
+ @delegate_hash = {}
31
+ end
32
+
33
+ def key?(key)
34
+ delegate_hash.key?(key) || values.key?(key) || types.key?(key)
35
+ end
36
+
37
+ def [](key)
38
+ delegate_hash[key] || assign_default_value(key)
39
+ end
40
+
41
+ def []=(key, value)
42
+ if frozen?
43
+ raise RuntimeError, "Can't modify frozen hash"
44
+ end
45
+ delegate_hash[key] = value
46
+ end
47
+
48
+ def initialized_keys
49
+ delegate_hash.keys | values.keys
50
+ end
51
+
52
+ def initialize_dup(_)
53
+ @delegate_hash = delegate_hash.transform_values(&:dup)
54
+ super
55
+ end
56
+
57
+ protected
58
+
59
+ attr_reader :types, :values, :additional_types, :delegate_hash
60
+
61
+ private
62
+
63
+ def assign_default_value(name)
64
+ type = additional_types.fetch(name, types[name])
65
+ value_present = true
66
+ value = values.fetch(name) { value_present = false }
67
+
68
+ if value_present
69
+ delegate_hash[name] = Attribute.from_database(name, value, type)
70
+ elsif types.key?(name)
71
+ delegate_hash[name] = Attribute.uninitialized(name, type)
23
72
  end
73
+ end
24
74
 
25
- def add_uninitialized_attributes(attributes)
26
- types.each_key do |name|
27
- next if attributes.key? name
28
- type = types[name]
29
- attributes[name] =
30
- Attribute.uninitialized(name, type)
31
- end
75
+ def materialize
76
+ unless @materialized
77
+ values.each_key { |key| self[key] }
78
+ types.each_key { |key| self[key] }
79
+ @materialized = true
32
80
  end
81
+ delegate_hash
33
82
  end
34
83
  end
35
84
  end
@@ -6,7 +6,9 @@ module ActiveRecord
6
6
 
7
7
  included do
8
8
  class_attribute :user_provided_columns, instance_accessor: false # :internal:
9
+ class_attribute :user_provided_defaults, instance_accessor: false # :internal:
9
10
  self.user_provided_columns = {}
11
+ self.user_provided_defaults = {}
10
12
  end
11
13
 
12
14
  module ClassMethods # :nodoc:
@@ -77,7 +79,11 @@ module ActiveRecord
77
79
  name = name.to_s
78
80
  clear_caches_calculated_from_columns
79
81
  # Assign a new hash to ensure that subclasses do not share a hash
80
- self.user_provided_columns = user_provided_columns.merge(name => connection.new_column(name, options[:default], cast_type))
82
+ self.user_provided_columns = user_provided_columns.merge(name => cast_type)
83
+
84
+ if options.key?(:default)
85
+ self.user_provided_defaults = user_provided_defaults.merge(name => options[:default])
86
+ end
81
87
  end
82
88
 
83
89
  # Returns an array of column objects for the table associated with this class.
@@ -99,11 +105,18 @@ module ActiveRecord
99
105
 
100
106
  def add_user_provided_columns(schema_columns)
101
107
  existing_columns = schema_columns.map do |column|
102
- user_provided_columns[column.name] || column
108
+ new_type = user_provided_columns[column.name]
109
+ if new_type
110
+ column.with_type(new_type)
111
+ else
112
+ column
113
+ end
103
114
  end
104
115
 
105
116
  existing_column_names = existing_columns.map(&:name)
106
- new_columns = user_provided_columns.except(*existing_column_names).values
117
+ new_columns = user_provided_columns.except(*existing_column_names).map do |(name, type)|
118
+ connection.new_column(name, nil, type)
119
+ end
107
120
 
108
121
  existing_columns + new_columns
109
122
  end
@@ -117,6 +130,10 @@ module ActiveRecord
117
130
  @content_columns = nil
118
131
  @default_attributes = nil
119
132
  end
133
+
134
+ def raw_default_values
135
+ super.merge(user_provided_defaults)
136
+ end
120
137
  end
121
138
  end
122
139
  end
@@ -287,10 +287,6 @@ module ActiveRecord
287
287
  "DEFAULT VALUES"
288
288
  end
289
289
 
290
- def limited_update_conditions(where_sql, quoted_table_name, quoted_primary_key)
291
- "WHERE #{quoted_primary_key} IN (SELECT #{quoted_primary_key} FROM #{quoted_table_name} #{where_sql})"
292
- end
293
-
294
290
  # Sanitizes the given LIMIT parameter in order to prevent SQL injection.
295
291
  #
296
292
  # The +limit+ may be anything that can evaluate to a string via #to_s. It
@@ -15,9 +15,7 @@ module ActiveRecord
15
15
  end
16
16
 
17
17
  def visit_AddColumn(o)
18
- sql_type = type_to_sql(o.type, o.limit, o.precision, o.scale)
19
- sql = "ADD #{quote_column_name(o.name)} #{sql_type}"
20
- add_column_options!(sql, column_options(o))
18
+ "ADD #{accept(o)}"
21
19
  end
22
20
 
23
21
  private
@@ -124,8 +124,8 @@ module ActiveRecord
124
124
  # which is one of the following:
125
125
  # <tt>:primary_key</tt>, <tt>:string</tt>, <tt>:text</tt>,
126
126
  # <tt>:integer</tt>, <tt>:float</tt>, <tt>:decimal</tt>,
127
- # <tt>:datetime</tt>, <tt>:timestamp</tt>, <tt>:time</tt>,
128
- # <tt>:date</tt>, <tt>:binary</tt>, <tt>:boolean</tt>.
127
+ # <tt>:datetime</tt>, <tt>:time</tt>, <tt>:date</tt>,
128
+ # <tt>:binary</tt>, <tt>:boolean</tt>.
129
129
  #
130
130
  # You may use a type not in this list as long as it is supported by your
131
131
  # database (for example, "polygon" in MySQL), but this will not be database
@@ -226,7 +226,7 @@ module ActiveRecord
226
226
  # t.integer :shop_id, :creator_id
227
227
  # t.string :item_number, index: true
228
228
  # t.string :name, :value, default: "Untitled"
229
- # t.timestamps
229
+ # t.timestamps null: false
230
230
  # end
231
231
  #
232
232
  # There's a short-hand method for each of the type values declared at the top. And then there's
@@ -287,7 +287,9 @@ module ActiveRecord
287
287
  end
288
288
 
289
289
  # Appends <tt>:datetime</tt> columns <tt>:created_at</tt> and
290
- # <tt>:updated_at</tt> to the table.
290
+ # <tt>:updated_at</tt> to the table. See SchemaStatements#add_timestamps
291
+ #
292
+ # t.timestamps null: false
291
293
  def timestamps(*args)
292
294
  options = args.extract_options!
293
295
  emit_warning_if_null_unspecified(options)
@@ -412,10 +414,10 @@ module ActiveRecord
412
414
  # end
413
415
  #
414
416
  class Table
415
- include TimestampDefaultDeprecation
417
+ attr_reader :name
416
418
 
417
419
  def initialize(table_name, base)
418
- @table_name = table_name
420
+ @name = table_name
419
421
  @base = base
420
422
  end
421
423
 
@@ -425,12 +427,12 @@ module ActiveRecord
425
427
  # ====== Creating a simple column
426
428
  # t.column(:name, :string)
427
429
  def column(column_name, type, options = {})
428
- @base.add_column(@table_name, column_name, type, options)
430
+ @base.add_column(name, column_name, type, options)
429
431
  end
430
432
 
431
433
  # Checks to see if a column exists. See SchemaStatements#column_exists?
432
434
  def column_exists?(column_name, type = nil, options = {})
433
- @base.column_exists?(@table_name, column_name, type, options)
435
+ @base.column_exists?(name, column_name, type, options)
434
436
  end
435
437
 
436
438
  # Adds a new index to the table. +column_name+ can be a single Symbol, or
@@ -443,27 +445,26 @@ module ActiveRecord
443
445
  # ====== Creating a named index
444
446
  # t.index([:branch_id, :party_id], unique: true, name: 'by_branch_party')
445
447
  def index(column_name, options = {})
446
- @base.add_index(@table_name, column_name, options)
448
+ @base.add_index(name, column_name, options)
447
449
  end
448
450
 
449
451
  # Checks to see if an index exists. See SchemaStatements#index_exists?
450
452
  def index_exists?(column_name, options = {})
451
- @base.index_exists?(@table_name, column_name, options)
453
+ @base.index_exists?(name, column_name, options)
452
454
  end
453
455
 
454
456
  # Renames the given index on the table.
455
457
  #
456
458
  # t.rename_index(:user_id, :account_id)
457
459
  def rename_index(index_name, new_index_name)
458
- @base.rename_index(@table_name, index_name, new_index_name)
460
+ @base.rename_index(name, index_name, new_index_name)
459
461
  end
460
462
 
461
463
  # Adds timestamps (+created_at+ and +updated_at+) columns to the table. See SchemaStatements#add_timestamps
462
464
  #
463
- # t.timestamps
465
+ # t.timestamps null: false
464
466
  def timestamps(options = {})
465
- emit_warning_if_null_unspecified(options)
466
- @base.add_timestamps(@table_name, options)
467
+ @base.add_timestamps(name, options)
467
468
  end
468
469
 
469
470
  # Changes the column's definition according to the new options.
@@ -472,7 +473,7 @@ module ActiveRecord
472
473
  # t.change(:name, :string, limit: 80)
473
474
  # t.change(:description, :text)
474
475
  def change(column_name, type, options = {})
475
- @base.change_column(@table_name, column_name, type, options)
476
+ @base.change_column(name, column_name, type, options)
476
477
  end
477
478
 
478
479
  # Sets a new default value for a column. See SchemaStatements#change_column_default
@@ -480,7 +481,7 @@ module ActiveRecord
480
481
  # t.change_default(:qualification, 'new')
481
482
  # t.change_default(:authorized, 1)
482
483
  def change_default(column_name, default)
483
- @base.change_column_default(@table_name, column_name, default)
484
+ @base.change_column_default(name, column_name, default)
484
485
  end
485
486
 
486
487
  # Removes the column(s) from the table definition.
@@ -488,7 +489,7 @@ module ActiveRecord
488
489
  # t.remove(:qualification)
489
490
  # t.remove(:qualification, :experience)
490
491
  def remove(*column_names)
491
- @base.remove_columns(@table_name, *column_names)
492
+ @base.remove_columns(name, *column_names)
492
493
  end
493
494
 
494
495
  # Removes the given index from the table.
@@ -502,21 +503,21 @@ module ActiveRecord
502
503
  # ====== Remove the index named by_branch_party in the table_name table
503
504
  # t.remove_index name: :by_branch_party
504
505
  def remove_index(options = {})
505
- @base.remove_index(@table_name, options)
506
+ @base.remove_index(name, options)
506
507
  end
507
508
 
508
509
  # Removes the timestamp columns (+created_at+ and +updated_at+) from the table.
509
510
  #
510
511
  # t.remove_timestamps
511
512
  def remove_timestamps
512
- @base.remove_timestamps(@table_name)
513
+ @base.remove_timestamps(name)
513
514
  end
514
515
 
515
516
  # Renames a column.
516
517
  #
517
518
  # t.rename(:description, :name)
518
519
  def rename(column_name, new_column_name)
519
- @base.rename_column(@table_name, column_name, new_column_name)
520
+ @base.rename_column(name, column_name, new_column_name)
520
521
  end
521
522
 
522
523
  # Adds a reference. Optionally adds a +type+ column, if <tt>:polymorphic</tt> option is provided.
@@ -531,7 +532,7 @@ module ActiveRecord
531
532
  def references(*args)
532
533
  options = args.extract_options!
533
534
  args.each do |ref_name|
534
- @base.add_reference(@table_name, ref_name, options)
535
+ @base.add_reference(name, ref_name, options)
535
536
  end
536
537
  end
537
538
  alias :belongs_to :references
@@ -546,7 +547,7 @@ module ActiveRecord
546
547
  def remove_references(*args)
547
548
  options = args.extract_options!
548
549
  args.each do |ref_name|
549
- @base.remove_reference(@table_name, ref_name, options)
550
+ @base.remove_reference(name, ref_name, options)
550
551
  end
551
552
  end
552
553
  alias :remove_belongs_to :remove_references
@@ -558,8 +559,8 @@ module ActiveRecord
558
559
  [:string, :text, :integer, :float, :decimal, :datetime, :timestamp, :time, :date, :binary, :boolean].each do |column_type|
559
560
  define_method column_type do |*args|
560
561
  options = args.extract_options!
561
- args.each do |name|
562
- @base.add_column(@table_name, name, column_type, options)
562
+ args.each do |column_name|
563
+ @base.add_column(name, column_name, column_type, options)
563
564
  end
564
565
  end
565
566
  end