activerecord 3.2.22.4 → 4.0.13

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 (173) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +2799 -617
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +23 -32
  5. data/examples/performance.rb +1 -1
  6. data/lib/active_record/aggregations.rb +40 -34
  7. data/lib/active_record/association_relation.rb +22 -0
  8. data/lib/active_record/associations/alias_tracker.rb +4 -2
  9. data/lib/active_record/associations/association.rb +60 -46
  10. data/lib/active_record/associations/association_scope.rb +46 -40
  11. data/lib/active_record/associations/belongs_to_association.rb +17 -4
  12. data/lib/active_record/associations/belongs_to_polymorphic_association.rb +1 -1
  13. data/lib/active_record/associations/builder/association.rb +81 -28
  14. data/lib/active_record/associations/builder/belongs_to.rb +73 -56
  15. data/lib/active_record/associations/builder/collection_association.rb +54 -40
  16. data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +23 -41
  17. data/lib/active_record/associations/builder/has_many.rb +8 -64
  18. data/lib/active_record/associations/builder/has_one.rb +13 -50
  19. data/lib/active_record/associations/builder/singular_association.rb +13 -13
  20. data/lib/active_record/associations/collection_association.rb +130 -96
  21. data/lib/active_record/associations/collection_proxy.rb +916 -63
  22. data/lib/active_record/associations/has_and_belongs_to_many_association.rb +15 -13
  23. data/lib/active_record/associations/has_many_association.rb +35 -8
  24. data/lib/active_record/associations/has_many_through_association.rb +37 -17
  25. data/lib/active_record/associations/has_one_association.rb +42 -19
  26. data/lib/active_record/associations/has_one_through_association.rb +1 -1
  27. data/lib/active_record/associations/join_dependency/join_association.rb +39 -22
  28. data/lib/active_record/associations/join_dependency/join_base.rb +2 -2
  29. data/lib/active_record/associations/join_dependency/join_part.rb +21 -8
  30. data/lib/active_record/associations/join_dependency.rb +30 -9
  31. data/lib/active_record/associations/join_helper.rb +1 -11
  32. data/lib/active_record/associations/preloader/association.rb +29 -33
  33. data/lib/active_record/associations/preloader/collection_association.rb +1 -1
  34. data/lib/active_record/associations/preloader/has_and_belongs_to_many.rb +2 -2
  35. data/lib/active_record/associations/preloader/has_many_through.rb +6 -2
  36. data/lib/active_record/associations/preloader/has_one.rb +1 -1
  37. data/lib/active_record/associations/preloader/through_association.rb +13 -17
  38. data/lib/active_record/associations/preloader.rb +20 -43
  39. data/lib/active_record/associations/singular_association.rb +11 -11
  40. data/lib/active_record/associations/through_association.rb +3 -3
  41. data/lib/active_record/associations.rb +223 -282
  42. data/lib/active_record/attribute_assignment.rb +134 -154
  43. data/lib/active_record/attribute_methods/before_type_cast.rb +44 -5
  44. data/lib/active_record/attribute_methods/dirty.rb +36 -29
  45. data/lib/active_record/attribute_methods/primary_key.rb +45 -31
  46. data/lib/active_record/attribute_methods/query.rb +5 -4
  47. data/lib/active_record/attribute_methods/read.rb +67 -90
  48. data/lib/active_record/attribute_methods/serialization.rb +133 -70
  49. data/lib/active_record/attribute_methods/time_zone_conversion.rb +51 -45
  50. data/lib/active_record/attribute_methods/write.rb +34 -39
  51. data/lib/active_record/attribute_methods.rb +268 -108
  52. data/lib/active_record/autosave_association.rb +80 -73
  53. data/lib/active_record/base.rb +54 -451
  54. data/lib/active_record/callbacks.rb +60 -22
  55. data/lib/active_record/coders/yaml_column.rb +18 -21
  56. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +347 -197
  57. data/lib/active_record/connection_adapters/abstract/database_limits.rb +9 -0
  58. data/lib/active_record/connection_adapters/abstract/database_statements.rb +146 -138
  59. data/lib/active_record/connection_adapters/abstract/query_cache.rb +25 -19
  60. data/lib/active_record/connection_adapters/abstract/quoting.rb +19 -3
  61. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +151 -142
  62. data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +70 -0
  63. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +499 -217
  64. data/lib/active_record/connection_adapters/abstract/transaction.rb +208 -0
  65. data/lib/active_record/connection_adapters/abstract_adapter.rb +209 -44
  66. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +169 -61
  67. data/lib/active_record/connection_adapters/column.rb +67 -36
  68. data/lib/active_record/connection_adapters/connection_specification.rb +96 -0
  69. data/lib/active_record/connection_adapters/mysql2_adapter.rb +28 -29
  70. data/lib/active_record/connection_adapters/mysql_adapter.rb +200 -73
  71. data/lib/active_record/connection_adapters/postgresql/array_parser.rb +98 -0
  72. data/lib/active_record/connection_adapters/postgresql/cast.rb +160 -0
  73. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +240 -0
  74. data/lib/active_record/connection_adapters/postgresql/oid.rb +374 -0
  75. data/lib/active_record/connection_adapters/postgresql/quoting.rb +183 -0
  76. data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +30 -0
  77. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +508 -0
  78. data/lib/active_record/connection_adapters/postgresql_adapter.rb +544 -899
  79. data/lib/active_record/connection_adapters/schema_cache.rb +76 -16
  80. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +595 -16
  81. data/lib/active_record/connection_handling.rb +98 -0
  82. data/lib/active_record/core.rb +472 -0
  83. data/lib/active_record/counter_cache.rb +107 -108
  84. data/lib/active_record/dynamic_matchers.rb +115 -63
  85. data/lib/active_record/errors.rb +36 -18
  86. data/lib/active_record/explain.rb +15 -63
  87. data/lib/active_record/explain_registry.rb +30 -0
  88. data/lib/active_record/explain_subscriber.rb +8 -4
  89. data/lib/active_record/fixture_set/file.rb +55 -0
  90. data/lib/active_record/fixtures.rb +159 -155
  91. data/lib/active_record/inheritance.rb +93 -59
  92. data/lib/active_record/integration.rb +8 -8
  93. data/lib/active_record/locale/en.yml +8 -1
  94. data/lib/active_record/locking/optimistic.rb +39 -43
  95. data/lib/active_record/locking/pessimistic.rb +4 -4
  96. data/lib/active_record/log_subscriber.rb +19 -9
  97. data/lib/active_record/migration/command_recorder.rb +102 -33
  98. data/lib/active_record/migration/join_table.rb +15 -0
  99. data/lib/active_record/migration.rb +411 -173
  100. data/lib/active_record/model_schema.rb +81 -94
  101. data/lib/active_record/nested_attributes.rb +173 -131
  102. data/lib/active_record/null_relation.rb +67 -0
  103. data/lib/active_record/persistence.rb +254 -106
  104. data/lib/active_record/query_cache.rb +18 -36
  105. data/lib/active_record/querying.rb +19 -15
  106. data/lib/active_record/railtie.rb +113 -38
  107. data/lib/active_record/railties/console_sandbox.rb +3 -4
  108. data/lib/active_record/railties/controller_runtime.rb +4 -3
  109. data/lib/active_record/railties/databases.rake +115 -368
  110. data/lib/active_record/railties/jdbcmysql_error.rb +1 -1
  111. data/lib/active_record/readonly_attributes.rb +7 -3
  112. data/lib/active_record/reflection.rb +110 -61
  113. data/lib/active_record/relation/batches.rb +29 -29
  114. data/lib/active_record/relation/calculations.rb +155 -125
  115. data/lib/active_record/relation/delegation.rb +94 -18
  116. data/lib/active_record/relation/finder_methods.rb +151 -203
  117. data/lib/active_record/relation/merger.rb +188 -0
  118. data/lib/active_record/relation/predicate_builder.rb +85 -42
  119. data/lib/active_record/relation/query_methods.rb +793 -146
  120. data/lib/active_record/relation/spawn_methods.rb +43 -150
  121. data/lib/active_record/relation.rb +293 -173
  122. data/lib/active_record/result.rb +48 -7
  123. data/lib/active_record/runtime_registry.rb +17 -0
  124. data/lib/active_record/sanitization.rb +41 -54
  125. data/lib/active_record/schema.rb +19 -12
  126. data/lib/active_record/schema_dumper.rb +41 -41
  127. data/lib/active_record/schema_migration.rb +46 -0
  128. data/lib/active_record/scoping/default.rb +56 -52
  129. data/lib/active_record/scoping/named.rb +78 -103
  130. data/lib/active_record/scoping.rb +54 -124
  131. data/lib/active_record/serialization.rb +6 -2
  132. data/lib/active_record/serializers/xml_serializer.rb +9 -15
  133. data/lib/active_record/statement_cache.rb +26 -0
  134. data/lib/active_record/store.rb +131 -15
  135. data/lib/active_record/tasks/database_tasks.rb +204 -0
  136. data/lib/active_record/tasks/firebird_database_tasks.rb +56 -0
  137. data/lib/active_record/tasks/mysql_database_tasks.rb +144 -0
  138. data/lib/active_record/tasks/oracle_database_tasks.rb +45 -0
  139. data/lib/active_record/tasks/postgresql_database_tasks.rb +90 -0
  140. data/lib/active_record/tasks/sqlite_database_tasks.rb +51 -0
  141. data/lib/active_record/tasks/sqlserver_database_tasks.rb +48 -0
  142. data/lib/active_record/test_case.rb +67 -38
  143. data/lib/active_record/timestamp.rb +16 -11
  144. data/lib/active_record/transactions.rb +73 -51
  145. data/lib/active_record/validations/associated.rb +19 -13
  146. data/lib/active_record/validations/presence.rb +65 -0
  147. data/lib/active_record/validations/uniqueness.rb +110 -57
  148. data/lib/active_record/validations.rb +18 -17
  149. data/lib/active_record/version.rb +7 -6
  150. data/lib/active_record.rb +63 -45
  151. data/lib/rails/generators/active_record/migration/migration_generator.rb +45 -8
  152. data/lib/rails/generators/active_record/{model/templates/migration.rb → migration/templates/create_table_migration.rb} +4 -0
  153. data/lib/rails/generators/active_record/migration/templates/migration.rb +20 -15
  154. data/lib/rails/generators/active_record/model/model_generator.rb +5 -4
  155. data/lib/rails/generators/active_record/model/templates/model.rb +4 -6
  156. data/lib/rails/generators/active_record/model/templates/module.rb +1 -1
  157. data/lib/rails/generators/active_record.rb +3 -5
  158. metadata +43 -29
  159. data/examples/associations.png +0 -0
  160. data/lib/active_record/attribute_methods/deprecated_underscore_read.rb +0 -32
  161. data/lib/active_record/connection_adapters/abstract/connection_specification.rb +0 -191
  162. data/lib/active_record/connection_adapters/sqlite_adapter.rb +0 -583
  163. data/lib/active_record/dynamic_finder_match.rb +0 -68
  164. data/lib/active_record/dynamic_scope_match.rb +0 -23
  165. data/lib/active_record/fixtures/file.rb +0 -65
  166. data/lib/active_record/identity_map.rb +0 -162
  167. data/lib/active_record/observer.rb +0 -121
  168. data/lib/active_record/session_store.rb +0 -360
  169. data/lib/rails/generators/active_record/migration.rb +0 -15
  170. data/lib/rails/generators/active_record/observer/observer_generator.rb +0 -15
  171. data/lib/rails/generators/active_record/observer/templates/observer.rb +0 -4
  172. data/lib/rails/generators/active_record/session_migration/session_migration_generator.rb +0 -25
  173. data/lib/rails/generators/active_record/session_migration/templates/migration.rb +0 -12
data/CHANGELOG.md CHANGED
@@ -1,1014 +1,3196 @@
1
- ## Rails 3.2.22 (Jun 16, 2015) ##
1
+ ## Rails 4.0.13 (January 6, 2015) ##
2
2
 
3
- * No changes.
3
+ * Renaming a table in pg also renames the primary key index.
4
4
 
5
+ Fixes #12856
5
6
 
6
- ## Rails 3.2.19 (Jul 2, 2014) ##
7
+ *Sean Griffin*
7
8
 
8
- * Fix SQL Injection Vulnerability in 'bitstring' quoting.
9
+ * Make it possible to access fixtures excluded by a `default_scope`.
9
10
 
10
- Fixes CVE-2014-3482.
11
-
12
- *Rafael Mendonça França*
11
+ *Yves Senn*
13
12
 
13
+ * `timestamps` and `add_timestamps` passes additional options along.
14
+ (like `null: false`)
14
15
 
15
- ## Rails 3.2.18 (May 6, 2014) ##
16
+ Closes #17624.
16
17
 
17
- * No changes.
18
+ *Yves Senn*
18
19
 
19
20
 
20
- ## Rails 3.2.17 (Feb 18, 2014) ##
21
+ ## Rails 4.0.12 (November 16, 2014) ##
21
22
 
22
- * No changes.
23
+ * Cache `CollectionAssociation#reader` proxies separately before and after
24
+ the owner has been saved so that the proxy is not cached without the
25
+ owner's id.
23
26
 
27
+ *Ben Woosley*
24
28
 
25
- ## Rails 3.2.16 (Dec 3, 2013) ##
26
29
 
27
- * No changes.
30
+ ## Rails 4.0.11.1 (November 19, 2014) ##
28
31
 
32
+ *No changes*
29
33
 
30
- ## Rails 3.2.15 (Oct 16, 2013) ##
31
34
 
32
- * When calling the method .find_or_initialize_by_* from a collection_proxy
33
- it should set the inverse_of relation even when the entry was found on the db.
35
+ ## Rails 4.0.11 (September 11, 2014) ##
34
36
 
35
- *arthurnn*
37
+ *No changes*
36
38
 
37
- * Callbacks on has_many should access the in memory parent if a inverse_of is set.
38
39
 
39
- *arthurnn*
40
+ ## Rails 4.0.10 (September 11, 2014) ##
40
41
 
41
- * Fix `FinderMethods#last` unscoped primary key.
42
+ * Fixed a regression where whitespaces were stripped from DISTINCT queries in
43
+ PostgreSQL.
42
44
 
43
- Fixes #11917.
45
+ *Agis Anastasopoulos*
44
46
 
45
- *Eugene Kalenkovich*
47
+ Fixes #16623.
46
48
 
47
- * Load fixtures from linked folders.
49
+ * Fix regression on after_commit that didn't fire when having nested transactions.
48
50
 
49
- *Kassio Borges*
51
+ Fixes #16425
50
52
 
51
- * When using optimistic locking, `update` was not passing the column to `quote_value`
52
- to allow the connection adapter to properly determine how to quote the value. This was
53
- affecting certain databases that use specific colmn types.
53
+ *arthurnn*
54
54
 
55
- Fixes: #6763
55
+ * Define `id_was` to get the previous value of the primary key.
56
56
 
57
- *Alfred Wong*
57
+ Currently when we call id_was and we have a custom primary key name
58
+ Active Record will return the current value of the primary key. This
59
+ make impossible to correctly do an update operation if you change the
60
+ id.
58
61
 
62
+ Fixes #16413.
59
63
 
60
- ## Rails 3.2.14 (Jul 22, 2013) ##
64
+ *Rafael Mendonça França*
61
65
 
62
- * Fix merge error when Equality LHS is non-attribute.
63
- Backport of #7380.
66
+ * Fixed error in `reset_counters` when associations have `select` scope.
67
+ (Call to `count` generates invalid SQL.)
64
68
 
65
- *Karmes Alexander*
69
+ *Cade Truitt*
66
70
 
67
- * Do not re-create destroyed association when saving the parent object.
71
+ * After a successful `reload`, `new_record?` is always false.
68
72
 
69
- Fixes #11450.
73
+ Fixes #12101.
70
74
 
71
- *Paul Nikitochkin*
75
+ *Matthew Draper*
72
76
 
73
- * Do not shallow the original exception in `exec_cache` on PostgreSQL adapter.
77
+ * `has_many :through` associations will no longer save the through record
78
+ twice when added in an `after_create` callback defined before the
79
+ associations.
74
80
 
75
- Fixes #11260.
81
+ *Sean Griffin*
76
82
 
77
- *Rafael Mendonça França*
83
+ * Correctly extract IPv6 addresses from `DATABASE_URI`: the square brackets
84
+ are part of the URI structure, not the actual host.
78
85
 
79
- * Fix `ActiveRecord::Store` incorrectly tracking changes of its attributes.
80
- Fixes #10373.
86
+ Fixes #15705.
81
87
 
82
- *Janko Marohnić*
88
+ *Andy Bakun*, *Aaron Stone*
83
89
 
84
- * Fix a bug that prevented the use of the default STI inheritance column
85
- (ActiveRecord::Base.inheritance_column = 'some_column'.)
90
+ * Don't error when quoting user defined types in PostgreSQL.
86
91
 
87
- *chapmajs + Takehiro Adachi*
92
+ Fixes #15697.
88
93
 
89
- * Fix mysql2 adapter raises the correct exception when executing a query on a
90
- closed connection.
94
+ *Sean Griffin*
91
95
 
92
- *Yves Senn*
96
+ * `ActiveRecord::FinderMethods.find` with block can handle proc parameter as
97
+ `Enumerable#find` does.
93
98
 
94
- * Fixes bug where `Company.new.contract_ids` would incorrectly load
95
- all non-associated contracts.
99
+ Fixes #15382.
96
100
 
97
- Example:
101
+ *James Yang*
98
102
 
99
- company = Company.new # Company has many :contracts
103
+ * `ActiveRecord::SchemaMigration` has no primary key regardless of the
104
+ `primary_key_prefix_type` configuration.
100
105
 
101
- # before
102
- company.contract_ids # => SELECT ... WHERE `contracts`.`company_id` IS NULL
106
+ Fixes #15051.
103
107
 
104
- # after
105
- company.contract_ids # => []
108
+ *JoseLuis Torres*, *Yves Senn*
106
109
 
107
- *Jared Armstrong*
110
+ * `rake db:migrate:status` works with legacy migration numbers like `00018_xyz.rb`.
108
111
 
109
- * Fix the `:primary_key` option for `has_many` associations.
110
- Fixes #10693.
112
+ Fixes #15538.
111
113
 
112
114
  *Yves Senn*
113
115
 
114
- * fixes bug introduced by #3329. Now, when autosaving associations,
115
- deletions happen before inserts and saves. This prevents a 'duplicate
116
- unique value' database error that would occur if a record being created had
117
- the same value on a unique indexed field as that of a record being destroyed.
116
+ * Fixed `columns_for_distinct` of postgresql adapter to work correctly
117
+ with orders without sort direction modifiers.
118
118
 
119
- Backport of #10417
119
+ *Nikolay Kondratyev*
120
120
 
121
- *Johnny Holton*
121
+ * `rake railties:install:migrations` respects the order of railties.
122
122
 
123
- * Fix that under some conditions, Active Record could produce invalid SQL of the sort:
124
- "SELECT DISTINCT DISTINCT".
123
+ *Arun Agrawal*
125
124
 
126
- Backport of #6792.
127
125
 
128
- *Ben Woosley*
126
+ ## Rails 4.0.9 (August 18, 2014) ##
127
+
128
+ * Check attributes passed to `create_with` and `where`.
129
129
 
130
- * Require `ActiveRecord::Base` in railtie hooks for rake_tasks, console and runner to
131
- avoid circular constant loading issues.
130
+ Fixes CVE-2014-3514.
132
131
 
133
- Backport #7695.
132
+ *Rafael Mendonça França*
134
133
 
135
- Fixes #7683 and #882
136
134
 
137
- *Ben Holley*
135
+ ## Rails 4.0.8 (July 2, 2014) ##
138
136
 
139
- * Maintain context for joins within ActiveRecord::Relation merges.
140
- Backport #10164.
137
+ * Fix regression added from the latest security fix.
141
138
 
142
- *Neeraj Singh + Andrew Horner*
139
+ *Sean Griffin*, *Matthew Draper*
143
140
 
144
- * Make sure the `EXPLAIN` command is never triggered by a `select_db` call.
145
141
 
146
- *Daniel Schierbeck*
142
+ ## Rails 4.0.7 (July 2, 2014) ##
147
143
 
148
- * Revert changes on `pluck` that was ignoring the select clause when the relation already
149
- has one. This caused a regression since it changed the behavior in a stable release.
144
+ * Fix SQL Injection Vulnerability in 'range' quoting.
150
145
 
151
- Fixes #9777.
146
+ Fixes CVE-2014-3483
152
147
 
153
148
  *Rafael Mendonça França*
154
149
 
155
- * Confirm a record has not already been destroyed before decrementing counter cache.
156
150
 
157
- *Ben Tucker*
151
+ ## Rails 4.0.6 (June 26, 2014) ##
158
152
 
159
- * Default values for PostgreSQL bigint types now get parsed and dumped to the
160
- schema correctly.
161
- Backport #10098.
153
+ * Fixed the inferred table name of a has_and_belongs_to_many auxiliar
154
+ table inside a schema.
162
155
 
163
- *Erik Peterson*
156
+ Fixes #14824
164
157
 
165
- * Removed warning when `auto_explain_threshold_in_seconds` is set and the
166
- connection adapter doesn't support explain.
167
- This is causing a regression since the Active Record Railtie is trying to
168
- connect to the development database in the application boot.
158
+ *Eric Chahin*
169
159
 
170
- *Rafael Mendonça França*
160
+ * Fix bug that added `table_name_prefix` and `table_name_suffix` to
161
+ extension names in PostgreSQL when migrating.
171
162
 
172
- * Do not reset `inheritance_column` when it's set explicitly.
173
- Backport of #5327.
163
+ *Joao Carlos*
174
164
 
175
- *kennyj + Fred Wu*
165
+ * `ActiveRecord::Relation::Merger#filter_binds` now compares equivalent symbols and
166
+ strings in column names as equal.
176
167
 
177
- * Fix a problem wrong exception is occured
178
- when raising no translatable exception in PostgreSQL.
168
+ This fixes a rare case in which more bind values are passed than there are
169
+ placeholders for them in the generated SQL statement, which can make PostgreSQL
170
+ throw a `StatementInvalid` exception.
179
171
 
180
- *kennyj*
172
+ *Nat Budin*
181
173
 
182
- * Resets the postgres search path in the structure.sql after the structure
183
- is dumped in order to find schema_migrations table when multiples schemas
184
- are used.
185
- Fixes #9796.
174
+ * Calling `delete_all` on an unloaded `CollectionProxy` no longer
175
+ generates a SQL statement containing each id of the collection:
186
176
 
187
- *Juan M. Cuello + Dembskiy Alexander*
177
+ Before:
188
178
 
189
- * Reload the association target if it's stale. `@stale_state` should be nil
190
- when a model isn't saved.
191
- Fixes #7526.
179
+ DELETE FROM `model` WHERE `model`.`parent_id` = 1
180
+ AND `model`.`id` IN (1, 2, 3...)
192
181
 
193
- *Larry Lv*
182
+ After:
194
183
 
195
- * Don't read CSV files during execution of `db:fixtures:load`. CSV support for
196
- fixtures was removed some time ago but the task was still loading them, even
197
- though later the code was looking for the related yaml file instead.
184
+ DELETE FROM `model` WHERE `model`.`parent_id` = 1
198
185
 
199
- *kennyj*
186
+ *Eileen M. Uchitelle*, *Aaron Patterson*
200
187
 
188
+ * Fix `stored_attributes` to correctly merge the details of stored
189
+ attributes defined in parent classes.
201
190
 
202
- ## Rails 3.2.13 (Mar 18, 2013) ##
191
+ Fixes #14672.
203
192
 
204
- * Chaining multiple preloaded scopes will correctly preload all the scopes
205
- at the same time.
193
+ *Brad Bennett*, *Jessica Yao*, *Lakshmi Parthasarathy*
206
194
 
207
- *Chris Geihsler*
195
+ * Fix bug where `ActiveRecord::Store` used a global `Hash` to keep track of
196
+ all registered `stored_attributes`. Now every subclass of
197
+ `ActiveRecord::Base` has it's own `Hash`.
208
198
 
209
- * Reverted 921a296a3390192a71abeec6d9a035cc6d1865c8, 'Quote numeric values
210
- compared to string columns.' This caused several regressions.
199
+ *Yves Senn*
211
200
 
212
- *Steve Klabnik*
201
+ * `change_column_default` allows `[]` as argument to `change_column_default`.
213
202
 
214
- * Fix overriding of attributes by `default_scope` on `ActiveRecord::Base#dup`.
203
+ Fixes #11586.
215
204
 
216
- *Hiroshige UMINO*
205
+ *Yves Senn*
217
206
 
218
- * Fix issue with overriding Active Record reader methods with a composed object
219
- and using that attribute as the scope of a `uniqueness_of` validation.
220
- Backport #7072.
207
+ * Fixed has_and_belongs_to_many's CollectionAssociation size calculation.
221
208
 
222
- *Peter Brown*
209
+ has_and_belongs_to_many should not include new records as part of
210
+ `#count_records` as new records are already counted.
223
211
 
224
- * Sqlite now preserves custom primary keys when copying or altering tables.
225
- Fixes #9367.
226
- Backport #2312.
212
+ Fixes #14914.
227
213
 
228
- *Sean Scally + Yves Senn*
214
+ *Fred Wu*
229
215
 
230
- * Preloading `has_many :through` associations with conditions won't
231
- cache the `:through` association. This will prevent invalid
232
- subsets to be cached.
233
- Fixes #8423.
234
- Backport #9252.
216
+ * Stringify all variables keys of MySQL connection configuration.
235
217
 
236
- Example:
218
+ When `sql_mode` variable for MySQL adapters set in configuration as `String`
219
+ was ignored and overwritten by strict mode option.
237
220
 
238
- class User
239
- has_many :posts
240
- has_many :recent_comments, -> { where('created_at > ?', 1.week.ago) }, :through => :posts
241
- end
221
+ Fixes #14895.
242
222
 
243
- a_user = User.includes(:recent_comments).first
223
+ *Paul Nikitochkin*
244
224
 
245
- # this is preloaded
246
- a_user.recent_comments
225
+ * Ensure SQLite3 statements are closed on errors.
247
226
 
248
- # fetching the recent_comments through the posts association won't preload it.
249
- a_user.posts
227
+ Fixes: #13631.
250
228
 
251
- *Yves Senn*
229
+ *Timur Alperovich*
252
230
 
253
- * Fix handling of dirty time zone aware attributes
231
+ * When joining tables with a default scope, ensure the generated table name
232
+ in the `ON` conditions from the default scope is correctly aliased.
254
233
 
255
- Previously, when `time_zone_aware_attributes` were enabled, after
256
- changing a datetime or timestamp attribute and then changing it back
257
- to the original value, `changed_attributes` still tracked the
258
- attribute as changed. This caused `[attribute]_changed?` and
259
- `changed?` methods to return true incorrectly.
234
+ Backports #14154.
260
235
 
261
- Example:
236
+ *Matt Jones*
262
237
 
263
- in_time_zone 'Paris' do
264
- order = Order.new
265
- original_time = Time.local(2012, 10, 10)
266
- order.shipped_at = original_time
267
- order.save
268
- order.changed? # => false
238
+ * Fix name collision with `Array#select!` with `Relation#select!`.
269
239
 
270
- # changing value
271
- order.shipped_at = Time.local(2013, 1, 1)
272
- order.changed? # => true
240
+ Fixes #14752.
273
241
 
274
- # reverting to original value
275
- order.shipped_at = original_time
276
- order.changed? # => false, used to return true
277
- end
242
+ *Earl St Sauver*
278
243
 
279
- Backport of #9073
280
- Fixes #8898
244
+ * When a destroyed record is duped, the dup is not `destroyed?`.
281
245
 
282
- *Lilibeth De La Cruz*
246
+ *Kuldeep Aggarwal*
283
247
 
284
- * Fix counter cache columns not updated when replacing `has_many :through`
285
- associations.
286
- Backport #8400.
287
- Fix #7630.
248
+ * Fixed has_many association to make it support irregular inflections.
288
249
 
289
- *Matthew Robertson*
250
+ Fixes #8928.
290
251
 
291
- * Don't update `column_defaults` when calling destructive methods on column with default value.
292
- Backport c517602.
293
- Fix #6115.
252
+ *arthurnn*, *Javier Goizueta*
294
253
 
295
- *Piotr Sarnacki + Aleksey Magusev + Alan Daud*
254
+ * Fixed a problem where count used with a grouping was not returning a Hash.
296
255
 
297
- * When `#count` is used in conjunction with `#uniq` we perform `count(:distinct => true)`.
298
- Fix #6865.
256
+ Fixes #14721.
299
257
 
300
- Example:
258
+ *Eric Chahin*
301
259
 
302
- relation.uniq.count # => SELECT COUNT(DISTINCT *)
260
+ * Do not quote uuid default value on `change_column`.
303
261
 
304
- *Yves Senn + Kaspar Schiess*
262
+ Fixes #14604.
305
263
 
306
- * Fix `ActiveRecord::Relation#pluck` when columns or tables are reserved words.
307
- Backport #7536.
308
- Fix #8968.
264
+ *Eric Chahin*
309
265
 
310
- *Ian Lesperance + Yves Senn + Kaspar Schiess*
266
+ * The comparison between `Relation` and `CollectionProxy` should be consistent.
311
267
 
312
- * Don't run explain on slow queries for database adapters that don't support it.
313
- Backport #6197.
268
+ Example:
314
269
 
315
- *Blake Smith*
270
+ author.posts == Post.where(author_id: author.id)
271
+ # => true
272
+ Post.where(author_id: author.id) == author.posts
273
+ # => true
316
274
 
317
- * Revert round usec when comparing timestamp attributes in the dirty tracking.
318
- Fixes #8460.
275
+ Fixes #13506.
319
276
 
320
- *Andrew White*
277
+ *Lauro Caetano*
321
278
 
322
- * Revert creation of through association models when using `collection=[]`
323
- on a `has_many :through` association from an unsaved model.
324
- Fix #7661, #8269.
279
+ * PostgreSQL adapter only warns once for every missing OID per connection.
325
280
 
326
- *Ernie Miller*
281
+ Fixes #14275.
327
282
 
328
- * Fix undefined method `to_i` when calling `new` on a scope that uses an
329
- Array; Fix FloatDomainError when setting integer column to NaN.
330
- Fixes #8718, #8734, #8757.
283
+ *Matthew Draper*, *Yves Senn*
331
284
 
332
- *Jason Stirk + Tristan Harward*
285
+ * Fix insertion of records via `has_many :through` association with scope.
333
286
 
334
- * Serialized attributes can be serialized in integer columns.
335
- Fix #8575.
287
+ Fixes #3548.
336
288
 
337
- *Rafael Mendonça França*
289
+ *Ivan Antropov*
338
290
 
339
- * Keep index names when using `alter_table` with sqlite3.
340
- Fix #3489.
341
- Backport #8522.
291
+ * Make possible to have an association called `records`.
342
292
 
343
- *Yves Senn*
293
+ Fixes #11645.
344
294
 
345
- * Recognize migrations placed in directories containing numbers and 'rb'.
346
- Fix #8492.
347
- Backport of #8500.
295
+ *prathamesh-sonpatki*
348
296
 
349
- *Yves Senn*
297
+ * `to_sql` on an association now matches the query that is actually executed, where it
298
+ could previously have incorrectly accrued additional conditions (e.g. as a result of
299
+ a previous query). `CollectionProxy` now always defers to the association scope's
300
+ `arel` method so the (incorrect) inherited one should be entirely concealed.
350
301
 
351
- * Add `ActiveRecord::Base.cache_timestamp_format` class attribute to control
352
- the format of the timestamp value in the cache key.
353
- This allows users to improve the precision of the cache key.
354
- Fixes #8195.
302
+ Fixes #14003.
355
303
 
356
- *Rafael Mendonça França*
304
+ *Jefferson Lai*
357
305
 
358
- * Add `:nsec` date format. This can be used to improve the precision of cache key.
359
- Please note that this format only works with Ruby 1.9, Ruby 1.8 will ignore it completely.
306
+ * Fixed error when using `with_options` with lambda.
360
307
 
361
- *Jamie Gaskins*
308
+ Fixes #9805.
362
309
 
363
- * Unscope `update_column(s)` query to ignore default scope.
310
+ *Lauro Caetano*
364
311
 
365
- When applying `default_scope` to a class with a where clause, using
366
- `update_column(s)` could generate a query that would not properly update
367
- the record due to the where clause from the `default_scope` being applied
368
- to the update query.
312
+ * Fixed error when specifying a non-empty default value on a PostgreSQL array column.
369
313
 
370
- class User < ActiveRecord::Base
371
- default_scope where(active: true)
372
- end
314
+ Fixes #10613.
373
315
 
374
- user = User.first
375
- user.active = false
376
- user.save!
316
+ *Luke Steensen*
377
317
 
378
- user.update_column(:active, true) # => false
318
+ * Fixed error where `#persisted?` throws `SystemStackError` for an unsaved model with a
319
+ custom primary key that didn't save due to validation error.
379
320
 
380
- In this situation we want to skip the default_scope clause and just
381
- update the record based on the primary key. With this change:
321
+ Fixes #14393.
382
322
 
383
- user.update_column(:active, true) # => true
323
+ *Chris Finne*
384
324
 
385
- Backport of #8436 fix.
325
+ * `rake db:structure:dump` only dumps schema information if the schema
326
+ migration table exists.
386
327
 
387
- *Carlos Antonio da Silva*
328
+ Fixes #14217.
388
329
 
389
- * Fix performance problem with primary_key method in PostgreSQL adapter when having many schemas.
390
- Uses pg_constraint table instead of pg_depend table which has many records in general.
391
- Fix #8414
330
+ *Yves Senn*
392
331
 
393
- *kennyj*
332
+ * Fix counter cache when association uses a `class_name`.
394
333
 
395
- * Do not instantiate intermediate Active Record objects when eager loading.
396
- These records caused `after_find` to run more than expected.
397
- Fix #3313
398
- Backport of #8403
334
+ Fixes #14369.
399
335
 
400
- *Yves Senn*
336
+ *arthurnn*
401
337
 
402
- * Fix `pluck` to work with joins. Backport of #4942.
338
+ * Add support for `Relation` be passed as parameter on `QueryCache#select_all`.
403
339
 
404
- *Carlos Antonio da Silva*
340
+ Fixes #14361.
405
341
 
406
- * Fix a problem with `translate_exception` method in a non English environment.
407
- Backport of #6397.
342
+ *arthurnn*
408
343
 
409
- *kennyj*
410
344
 
411
- * Fix dirty attribute checks for TimeZoneConversion with nil and blank
412
- datetime attributes. Setting a nil datetime to a blank string should not
413
- result in a change being flagged.
414
- Fixes #8310.
415
- Backport of #8311.
345
+ ## Rails 4.0.5 (May 6, 2014) ##
416
346
 
417
- *Alisdair McDiarmid*
347
+ *No changes*
418
348
 
419
- * Prevent mass assignment to the type column of polymorphic associations when using `build`.
420
- Fixes #8265.
421
- Backport of #8291.
422
349
 
423
- *Yves Senn*
350
+ ## Rails 4.0.4 (March 14, 2014) ##
424
351
 
425
- * When running migrations on Postgresql, the `:limit` option for `binary` and `text` columns is
426
- silently dropped.
427
- Previously, these migrations caused sql exceptions, because Postgresql doesn't support limits
428
- on these types.
352
+ * Only save has_one associations if record has changes.
353
+ Previously after save related callbacks, such as `#after_commit`, were triggered when the has_one
354
+ object did not get saved to the db.
429
355
 
430
- *Victor Costan*
356
+ *Alan Kennedy*
431
357
 
432
- * `#pluck` can be used on a relation with `select` clause.
433
- Fixes #7551.
434
- Backport of #8176.
358
+ * Fixed STI classes not defining an attribute method if there is a
359
+ conflicting private method defined on its ancestors.
435
360
 
436
- Example:
361
+ Fixes #11569.
437
362
 
438
- Topic.select([:approved, :id]).order(:id).pluck(:id)
363
+ *Godfrey Chan*
439
364
 
440
- *Yves Senn*
365
+ * Fix validation on uniqueness of empty association.
441
366
 
442
- * Use `nil?` instead of `blank?` to check whether dynamic finder with a bang
443
- should raise RecordNotFound.
444
- Fixes #7238.
367
+ *Evgeny Li*
445
368
 
446
- *Nikita Afanasenko*
369
+ * Perform necessary deeper encoding when hstore is inside an array.
447
370
 
448
- * Fix deleting from a HABTM join table upon destroying an object of a model
449
- with optimistic locking enabled.
450
- Fixes #5332.
371
+ Fixes #11135.
451
372
 
452
- *Nick Rogers*
373
+ *Josh Goodall*, *Genadi Samokovarov*
453
374
 
454
- * Use query cache/uncache when using ENV["DATABASE_URL"].
455
- Fixes #6951.
456
- Backport of #8074.
375
+ * Properly detect if a connection is still active before using it
376
+ in multi-threaded environments.
457
377
 
458
- *kennyj*
378
+ Fixes #12867.
459
379
 
460
- * Do not create useless database transaction when building `has_one` association.
380
+ *Kevin Casey*, *Matthew Draper*, *William (B.J.) Snow Orvis*
461
381
 
462
- Example:
382
+ * When inverting add_index use the index name if present instead of
383
+ the columns.
463
384
 
464
- User.has_one :profile
465
- User.new.build_profile
385
+ If there are two indices with matching columns and one of them is
386
+ explicitly named then reverting the migration adding the named one
387
+ would instead drop the unnamed one.
466
388
 
467
- Backport of #8154.
389
+ The inversion of add_index will now drop the index by its name if
390
+ it is present.
468
391
 
469
- *Bogdan Gusiev*
392
+ *Hubert Dąbrowski*
470
393
 
471
- * `AR::Base#attributes_before_type_cast` now returns unserialized values for serialized attributes.
394
+ * Make sure transaction state gets reset after a commit operation on the record.
472
395
 
473
- *Nikita Afanasenko*
396
+ If a new transaction was open inside a callback, the record was loosing track
397
+ of the transaction level state, and it was leaking that state.
474
398
 
475
- * Fix issue that raises `NameError` when overriding the `accepts_nested_attributes` in child classes.
399
+ Fixes #12566.
476
400
 
477
- Before:
401
+ *arthurnn*
478
402
 
479
- class Shared::Person < ActiveRecord::Base
480
- has_one :address
403
+ * PostgreSQL implementation of `SchemaStatements#index_name_exists?`.
481
404
 
482
- accepts_nested_attributes :address, :reject_if => :all_blank
483
- end
405
+ The database agnostic implementation does not detect with indexes that are
406
+ not supported by the ActiveRecord schema dumper. For example, expressions
407
+ indexes would not be detected.
484
408
 
485
- class Person < Shared::Person
486
- accepts_nested_attributes :address
487
- end
409
+ Fixes #11018.
488
410
 
489
- Person
490
- #=> NameError: method `address_attributes=' not defined in Person
411
+ *Jonathan Baudanza*
491
412
 
492
- After:
413
+ * Parsing PostgreSQL arrays with empty strings now works correctly.
493
414
 
494
- Person
495
- #=> Person(id: integer, ...)
415
+ Previously, if you tried to parse `{"1","","2","","3"}` the result
416
+ would be `["1","2","3"]`, removing the empty strings from the array,
417
+ which would be incorrect. Now it will correctly produce `["1","","2","","3"]`
418
+ as the result of parsing the above PostgreSQL array.
496
419
 
497
- Fixes #8131.
420
+ Fixes #13907.
498
421
 
499
- *Gabriel Sobrinho, Ricardo Henrique*
422
+ *Maurício Linhares*
500
423
 
424
+ * Fix regressions on `select_*` methods.
425
+ When `select_*` methods receive a `Relation` object, they should be able to get the arel/binds from it.
426
+ Also fix regressions on select_rows that was ignoring the binds.
501
427
 
502
- ## Rails 3.2.12 (Feb 11, 2013) ##
428
+ Fixes #7538, #12017, #13731, #12056.
503
429
 
504
- * Quote numeric values being compared to non-numeric columns. Otherwise,
505
- in some database, the string column values will be coerced to a numeric
506
- allowing 0, 0.0 or false to match any string starting with a non-digit.
430
+ *arthurnn*
507
431
 
508
- Example:
432
+ * Correctly send an user provided statement to a `lock!()` call.
509
433
 
510
- App.where(apikey: 0) # => SELECT * FROM users WHERE apikey = '0'
434
+ person.lock! 'FOR SHARE NOWAIT'
435
+ # Before: SELECT * ... LIMIT 1 FOR UPDATE
436
+ # After: SELECT * ... LIMIT 1 FOR SHARE NOWAIT
511
437
 
512
- *Dylan Smith*
438
+ Fixes #13788.
513
439
 
440
+ *Maurício Linhares*
514
441
 
515
- ## Rails 3.2.11 (Jan 8, 2013) ##
442
+ * Active Record objects can now be correctly dumped, loaded and dumped again without issues.
516
443
 
517
- * Fix querying with an empty hash *Damien Mathieu* [CVE-2013-0155]
444
+ Previously, if you did `YAML.dump`, `YAML.load` and then `YAML.dump` again
445
+ in an ActiveRecord model that used serialization it would fail at the last
446
+ dump due to the fields not being correctly serialized before being dumped
447
+ to YAML. Now it is possible to dump and load the same object as many times
448
+ as needed without any issues.
518
449
 
450
+ Fixes #13861.
519
451
 
520
- ## Rails 3.2.10 (Jan 2, 2013) ##
452
+ *Maurício Linhares*
521
453
 
522
- * CVE-2012-5664 options hashes should only be extracted if there are extra
523
- parameters
454
+ * `has_one` and `belongs_to` accessors don't add ORDER BY to the queries anymore.
524
455
 
456
+ Since Rails 4.0, we add an ORDER BY in the `first` method to ensure consistent results
457
+ among different database engines. But for singular associations this behavior is not needed
458
+ since we will have one record to return. As this ORDER BY option can lead some performance
459
+ issues we are removing it for singular associations accessors.
525
460
 
526
- ## Rails 3.2.9 (Nov 12, 2012) ##
461
+ Fixes #12623.
527
462
 
528
- * Fix `find_in_batches` crashing when IDs are strings and start option is not specified.
463
+ *Rafael Mendonça França*
529
464
 
530
- *Alexis Bernard*
465
+ * Fail early with "Primary key not included in the custom select clause"
466
+ in `find_in_batches`.
531
467
 
532
- * Fix issue with collection associations calling first(n)/last(n) and attempting
533
- to set the inverse association when `:inverse_of` was used. Fixes #8087.
468
+ Before this patch, the exception was raised after the first batch was
469
+ yielded to the block. This means that you only get it, when you hit the
470
+ `batch_size` treshold. This could shadow the issue in development.
534
471
 
535
- *Carlos Antonio da Silva*
472
+ *Alexander Balashov*
536
473
 
537
- * Fix bug when Column is trying to type cast boolean values to integer.
538
- Fixes #8067.
474
+ * ActiveRecord states are now correctly restored after a rollback for
475
+ models that did not define any transactional callbacks (i.e.
476
+ `after_commit`, `after_rollback` or `after_create`).
539
477
 
540
- *Rafael Mendonça França*
478
+ Fixes #13744.
541
479
 
542
- * Fix bug where `rake db:test:prepare` tries to load the structure.sql into development database.
543
- Fixes #8032.
480
+ *Godfrey Chan*
544
481
 
545
- *Grace Liu + Rafael Mendonça França*
482
+ * Add back `#yaml_initialize` method for Syck deserialization
546
483
 
547
- * Fixed support for `DATABASE_URL` environment variable for rake db tasks. *Grace Liu*
484
+ `ActiveRecord::Core#yaml_initialize` has been added back to support deserialization using
485
+ the Syck engine. This is to facilitate migration from Syck to Psych. Serialization support
486
+ will not been restored for Syck, Psych should be used to serialize YAML once its been
487
+ parsed with Syck.
548
488
 
549
- * Fix bug where `update_columns` and `update_column` would not let you update the primary key column.
489
+ *Blake Mesdag*, *arthurnn*
550
490
 
551
- *Henrik Nyh*
491
+ * Make `touch` fire the `after_commit` and `after_rollback` callbacks.
552
492
 
553
- * Decode URI encoded attributes on database connection URLs.
493
+ *Harry Brundage*
554
494
 
555
- *Shawn Veader*
495
+ * Don't try to get the subclass if the inheritance column doesn't exist
556
496
 
557
- * Fix AR#dup to nullify the validation errors in the dup'ed object. Previously the original
558
- and the dup'ed object shared the same errors.
497
+ The `subclass_from_attrs` method is called even if the column specified by
498
+ the `inheritance_column` setting doesn't exist. This prevents setting associations
499
+ via the attributes hash if the association name clashes with the value of the setting,
500
+ typically `:type`. This worked previously in Rails 3.2.
559
501
 
560
- *Christian Seiler*
502
+ *Ujjwal Thaakar*
561
503
 
562
- * Synchronize around deleting from the reserved connections hash.
563
- Fixes #7955
504
+ * Fix bug in `becomes!` when changing from the base model to a STI sub-class.
564
505
 
565
- * PostgreSQL adapter correctly fetches default values when using
566
- multiple schemas and domains in a db. Fixes #7914
506
+ Fixes #13272.
567
507
 
568
- *Arturo Pie*
508
+ *the-web-dev*, *Yves Senn*
569
509
 
570
- * Fix deprecation notice when loading a collection association that
571
- selects columns from other tables, if a new record was previously
572
- built using that association.
510
+ * Initialize version on Migration objects so that it can be used in a migration,
511
+ and it will be included in the announce message.
573
512
 
574
- *Ernie Miller*
513
+ *Dylan Thacker-Smith*
575
514
 
576
- * The postgres adapter now supports tables with capital letters.
577
- Fix #5920
515
+ * `change_table` now uses the current adapter's `update_table_definition`
516
+ method to retrieve a specific table definition.
517
+ This ensures that `change_table` and `create_table` will use
518
+ similar objects.
578
519
 
579
- *Yves Senn*
520
+ Fixes #13577 and #13503.
580
521
 
581
- * `CollectionAssociation#count` returns `0` without querying if the
582
- parent record is not persisted.
522
+ *Nishant Modak*, *Prathamesh Sonpatki*, *Rafael Mendonça França*
583
523
 
584
- Before:
524
+ * Fixed ActiveRecord::Store nil conversion TypeError when using YAML coder.
525
+ In case the YAML passed as paramter is nil, uses an empty string.
585
526
 
586
- person.pets.count
587
- # SELECT COUNT(*) FROM "pets" WHERE "pets"."person_id" IS NULL
588
- # => 0
527
+ Fixes #13570.
589
528
 
590
- After:
529
+ *Thales Oliveira*
591
530
 
592
- person.pets.count
593
- # fires without sql query
594
- # => 0
531
+ * Fix presence validator for association when the associated record responds to `to_a`.
595
532
 
596
- *Francesco Rodriguez*
533
+ *gmarik*
597
534
 
598
- * Fix `reset_counters` crashing on `has_many :through` associations.
599
- Fix #7822.
535
+ * Fix bug in `belongs_to` association with `touch: true`.
536
+ Associated records are no longer touched, when they are already destroyed.
600
537
 
601
- *lulalala*
538
+ Fixes #13445.
602
539
 
603
- * ConnectionPool recognizes checkout_timeout spec key as taking
604
- precedence over legacy wait_timeout spec key, can be used to avoid
605
- conflict with mysql2 use of wait_timeout. Closes #7684.
540
+ Example:
606
541
 
607
- *jrochkind*
542
+ # Given Comment has belongs_to :post, touch: true
543
+ comment.post.destroy
544
+ comment.destroy # no longer touches post
608
545
 
609
- * Rename field_changed? to _field_changed? so that users can create a field named field
546
+ *Paul Nikitochkin*
610
547
 
611
- *Akira Matsuda*, backported by *Steve Klabnik*
548
+ * Fixed `update_column`, `update_columns`, and `update_all` to correctly serialize
549
+ values for `array`, `hstore` and `json` column types in PostgreSQL.
612
550
 
613
- * Fix creation of through association models when using `collection=[]`
614
- on a `has_many :through` association from an unsaved model.
615
- Fix #7661.
551
+ Fixes #12261.
616
552
 
617
- *Ernie Miller*
553
+ *Tadas Tamosauskas*, *Carlos Antonio da Silva*
618
554
 
619
- * Explain only normal CRUD sql (select / update / insert / delete).
620
- Fix problem that explains unexplainable sql. Closes #7544 #6458.
555
+ * Do not consider PostgreSQL array columns as number or text columns.
621
556
 
622
- *kennyj*
557
+ The code uses these checks in several places to know what to do with a
558
+ particular column, for instance AR attribute query methods has a branch
559
+ like this:
623
560
 
624
- * Backport test coverage to ensure that PostgreSQL auto-reconnect functionality
625
- remains healthy.
561
+ if column.number?
562
+ !value.zero?
563
+ end
626
564
 
627
- *Steve Jorgensen*
565
+ This should never be true for array columns, since it would be the same
566
+ as running [].zero?, which results in a NoMethodError exception.
628
567
 
629
- * Use config['encoding'] instead of config['charset'] when executing
630
- databases.rake in the mysql/mysql2. A correct option for a database.yml
631
- is 'encoding'.
568
+ Fixing this by ensuring that array columns in PostgreSQL never return
569
+ true for number?/text? checks.
632
570
 
633
- *kennyj*
571
+ *Carlos Antonio da Silva*
634
572
 
635
- * Fix ConnectionAdapters::Column.type_cast_code integer conversion,
636
- to always convert values to integer calling #to_i. Fixes #7509.
573
+ * Fix a bug when assigning an array containing string numbers to a
574
+ PostgreSQL integer array column.
637
575
 
638
- *Thiago Pradi*
576
+ Fixes #13444.
639
577
 
640
- * Fix time column type casting for invalid time string values to correctly return nil.
578
+ Example:
641
579
 
642
- *Adam Meehan*
580
+ # Given Book#ratings is of type :integer, array: true
581
+ Book.new(ratings: [1, 2]) # worked before
582
+ Book.new(ratings: ['1', '2']) # now works as well
643
583
 
644
- * Fix `becomes` when using a configured `inheritance_column`.
584
+ *Damien Mathieu*
645
585
 
646
- *Yves Senn*
586
+ * `db:test:clone` and `db:test:prepare` must load Rails environment.
647
587
 
648
- * Fix `reset_counters` when there are multiple `belongs_to` association with the
649
- same foreign key and one of them have a counter cache.
650
- Fixes #5200.
588
+ `db:test:clone` and `db:test:prepare` use `ActiveRecord::Base`. configurations,
589
+ so we need to load the Rails environment, otherwise the config wont be in place.
651
590
 
652
- *Dave Desrochers*
591
+ *arthurnn*
653
592
 
654
- * Round usec when comparing timestamp attributes in the dirty tracking.
655
- Fixes #6975.
593
+ * Use the right column to type cast grouped calculations with custom expressions.
656
594
 
657
- *kennyj*
595
+ Fixes #13230.
658
596
 
659
- * Use inversed parent for first and last child of has_many association.
597
+ Example:
660
598
 
661
- *Ravil Bayramgalin*
599
+ # Before
600
+ Account.group(:firm_name).sum('0.01 * credit_limit')
601
+ # => { '37signals' => '0.5' }
662
602
 
663
- * Fix Column.microseconds and Column.fast_string_to_date to avoid converting
664
- timestamp seconds to a float, since it occasionally results in inaccuracies
665
- with microsecond-precision times. Fixes #7352.
603
+ # After
604
+ Account.group(:firm_name).sum('0.01 * credit_limit')
605
+ # => { '37signals' => 0.5 }
666
606
 
667
- *Ari Pollak*
607
+ *Paul Nikitochkin*
668
608
 
669
- * Fix `increment!`, `decrement!`, `toggle!` that was skipping callbacks.
670
- Fixes #7306.
609
+ * Support deprecated finder options when performing calculations
610
+ on an association.
671
611
 
672
- *Rafael Mendonça França*
612
+ Fixes #13165.
673
613
 
674
- * Fix AR#create to return an unsaved record when AR::RecordInvalid is
675
- raised. Fixes #3217.
614
+ *Garth Smedley*, *Yves Senn*
676
615
 
677
- *Dave Yeu*
616
+ * `ActiveRecord::ConnectionAdapters.string_to_time` respects
617
+ string with timezone (e.g. Wed, 04 Sep 2013 20:30:00 JST).
678
618
 
679
- * Remove unnecessary transaction when assigning has_one associations with a nil or equal value.
680
- Fix #7191.
619
+ Fixes #12278, #12459.
681
620
 
682
- *kennyj*
621
+ *kennyj*, *George Guimarães*
683
622
 
684
- * Allow store to work with an empty column.
685
- Fix #4840.
623
+ * Polymorphic `belongs_to` associations with the `touch: true` option set update the timestamps of
624
+ the old and new owner correctly when moved between owners of different types.
686
625
 
687
- *Jeremy Walker*
626
+ Example:
688
627
 
689
- * Remove prepared statement from system query in postgresql adapter.
690
- Fix #5872.
628
+ class Rating < ActiveRecord::Base
629
+ belongs_to :rateable, polymorphic: true, touch: true
630
+ end
691
631
 
692
- *Ivan Evtuhovich*
632
+ rating = Rating.create rateable: Song.find(1)
633
+ rating.update_attributes rateable: Book.find(2) # => timestamps of Song(1) and Book(2) are updated
693
634
 
694
- * Make sure `:environment` task is executed before `db:schema:load` or `db:structure:load`
695
- Fixes #4772.
635
+ *Severin Schoepke*
696
636
 
697
- *Seamus Abshere*
637
+ * `type_to_sql` returns a `String` for unmapped columns. This fixes an error
638
+ when using unmapped array types in combination with PostgreSQL's `array: true`.
698
639
 
640
+ Fixes #13146.
699
641
 
700
- ## Rails 3.2.8 (Aug 9, 2012) ##
642
+ Example:
701
643
 
702
- * Do not consider the numeric attribute as changed if the old value is zero and the new value
703
- is not a string.
704
- Fixes #7237.
644
+ change_colum :table, :column, :bigint, array: true
705
645
 
706
- *Rafael Mendonça França*
646
+ *Jens Fahnenbruck*, *Yves Senn*
707
647
 
708
- * Removes the deprecation of `update_attribute`. *fxn*
648
+ * Previously, the `has_one` macro incorrectly accepts the `counter_cache`
649
+ option due to a bug, although that options was never supported nor
650
+ functional on `has_one` and `has_one ... through` relationships. It now
651
+ correctly raises an `ArgumentError` when passed that option.
709
652
 
710
- * Reverted the deprecation of `composed_of`. *Rafael Mendonça França*
653
+ *Godfrey Chan*
711
654
 
712
- * Reverted the deprecation of `*_sql` association options. They will
713
- be deprecated in 4.0 instead. *Jon Leighton*
655
+ * Update counter cache on a has_many relationship regardless of default scope
714
656
 
715
- * Do not eager load AR session store. ActiveRecord::SessionStore depends on the abstract store
716
- in Action Pack. Eager loading this class would break client code that eager loads Active Record
717
- standalone.
718
- Fixes #7160
657
+ Fix #12952.
719
658
 
720
- *Xavier Noria*
659
+ *Uku Taht*
721
660
 
722
- * Do not set RAILS_ENV to "development" when using `db:test:prepare` and related rake tasks.
723
- This was causing the truncation of the development database data when using RSpec.
724
- Fixes #7175.
661
+ * Fix bug when validating the uniqueness of an aliased attribute.
725
662
 
726
- *Rafael Mendonça França*
663
+ Fixes #12402.
727
664
 
728
- ## Rails 3.2.7 (Jul 26, 2012) ##
665
+ *Lauro Caetano*
729
666
 
730
- * `:finder_sql` and `:counter_sql` options on collection associations
731
- are deprecated. Please transition to using scopes.
667
+ * Checks to see if the record contains the foreign key to set the inverse automatically.
732
668
 
733
- *Jon Leighton*
669
+ *Edo Balvers*
734
670
 
735
- * `:insert_sql` and `:delete_sql` options on `has_and_belongs_to_many`
736
- associations are deprecated. Please transition to using `has_many
737
- :through`
671
+ * Prevent the counter cache from being decremented twice when destroying
672
+ a record on a has_many :through association.
738
673
 
739
- *Jon Leighton*
674
+ Fixes #11079.
740
675
 
741
- * `composed_of` has been deprecated. You'll have to write your own accessor
742
- and mutator methods if you'd like to use value objects to represent some
743
- portion of your models.
676
+ *Dmitry Dedov*
744
677
 
745
- *Steve Klabnik*
678
+ * Fix bug where has_one associaton record update result in crash, when replaced with itself.
746
679
 
747
- * `update_attribute` has been deprecated. Use `update_column` if
748
- you want to bypass mass-assignment protection, validations, callbacks,
749
- and touching of updated_at. Otherwise please use `update_attributes`.
680
+ Fixes #12834.
750
681
 
751
- *Steve Klabnik*
682
+ *Denis Redozubov*, *Sergio Cambra*
752
683
 
753
- ## Rails 3.2.6 (Jun 12, 2012) ##
684
+ * Fix uninitialized constant TransactionState error when Marshall.load is used on an Active Record result.
754
685
 
755
- * protect against the nesting of hashes changing the
756
- table context in the next call to build_from_hash. This fix
757
- covers this case as well.
686
+ Fixes #12790.
758
687
 
759
- CVE-2012-2695
688
+ *Jason Ayre*
760
689
 
761
- * Revert earlier 'perf fix' (see 3.2.4 changelog / GH #6289). This
762
- change introduced a regression (GH #6609). assoc.clear and
763
- assoc.delete_all have loaded the association before doing the delete
764
- since at least Rails 2.3. Doing the delete without loading the
765
- records means that the `before_remove` and `after_remove` callbacks do
766
- not get invoked. Therefore, this change was less a fix a more an
767
- optimisation, which should only have gone into master.
690
+ * Do not add to scope includes values from through associations.
691
+ Fixed bug when providing `includes` in through association scope, and fetching targets.
768
692
 
769
- *Jon Leighton*
693
+ Example:
694
+ class Vendor < ActiveRecord::Base
695
+ has_many :relationships, -> { includes(:user) }
696
+ has_many :users, through: :relationships
697
+ end
770
698
 
771
- ## Rails 3.2.5 (Jun 1, 2012) ##
699
+ vendor = Vendor.first
772
700
 
773
- * Restore behavior of Active Record 3.2.3 scopes.
774
- A series of commits relating to preloading and scopes caused a regression.
701
+ # Before
775
702
 
776
- *Andrew White*
703
+ vendor.users.to_a # => Raises exception: not found `:user` for `User`
777
704
 
705
+ # After
778
706
 
779
- ## Rails 3.2.4 (May 31, 2012) ##
707
+ vendor.users.to_a # => No exception is raised
780
708
 
781
- * Perf fix: Don't load the records when doing assoc.delete_all.
782
- GH #6289. *Jon Leighton*
783
709
 
784
- * Association preloading shouldn't be affected by the current scoping.
785
- This could cause infinite recursion and potentially other problems.
786
- See GH #5667. *Jon Leighton*
710
+ Fixes #12242, #9517, #10240.
787
711
 
788
- * Datetime attributes are forced to be changed. GH #3965
712
+ *Paul Nikitochkin*
789
713
 
790
- * Fix attribute casting. GH #5549
714
+ * Save `has_one` association when primary key is manually set.
791
715
 
792
- * Fix #5667. Preloading should ignore scoping.
716
+ Fixes #12302.
793
717
 
794
- * Predicate builder should not recurse for determining where columns.
795
- Thanks to Ben Murphy for reporting this! CVE-2012-2661
718
+ *Lauro Caetano*
796
719
 
720
+ * Allow any version of BCrypt when using `has_secury_password`.
797
721
 
798
- ## Rails 3.2.3 (March 30, 2012) ##
722
+ *Mike Perham*
799
723
 
800
- * Added find_or_create_by_{attribute}! dynamic method. *Andrew White*
724
+ * Assign inet/cidr attribute with `nil` value for invalid address.
801
725
 
802
- * Whitelist all attribute assignment by default. Change the default for newly generated applications to whitelist all attribute assignment. Also update the generated model classes so users are reminded of the importance of attr_accessible. *NZKoz*
726
+ Example:
803
727
 
804
- * Update ActiveRecord::AttributeMethods#attribute_present? to return false for empty strings. *Jacobkg*
728
+ record = User.new
805
729
 
806
- * Fix associations when using per class databases. *larskanis*
730
+ record.logged_in_from_ip # is type of an inet or a cidr
807
731
 
808
- * Revert setting NOT NULL constraints in add_timestamps *fxn*
732
+ # Before:
733
+ record.logged_in_from_ip = 'bad ip address' # raise exception
809
734
 
810
- * Fix mysql to use proper text types. Fixes #3931. *kennyj*
735
+ # After:
736
+ record.logged_in_from_ip = 'bad ip address' # do not raise exception
737
+ record.logged_in_from_ip # => nil
738
+ record.logged_in_from_ip_before_type_cast # => 'bad ip address'
811
739
 
812
- * Fix #5069 - Protect foreign key from mass assignment through association builder. *byroot*
740
+ *Paul Nikitochkin*
813
741
 
742
+ * `rake db:structure:dump` no longer crashes when the port was specified as `Fixnum`.
814
743
 
815
- ## Rails 3.2.2 (March 1, 2012) ##
744
+ *Kenta Okamoto*
816
745
 
817
- * No changes.
746
+ * Fix a bug where rake db:structure:load crashed when the path contained
747
+ spaces.
818
748
 
749
+ *Kevin Mook*
819
750
 
820
- ## Rails 3.2.1 (January 26, 2012) ##
751
+ * `ActiveRecord::QueryMethods#unscope` unscopes negative equality
821
752
 
822
- * The threshold for auto EXPLAIN is ignored if there's no logger. *fxn*
753
+ Allows you to call `#unscope` on a relation with negative equality
754
+ operators, i.e. `Arel::Nodes::NotIn` and `Arel::Nodes::NotEqual` that have
755
+ been generated through the use of `where.not`.
823
756
 
824
- * Call `to_s` on the value passed to `table_name=`, in particular symbols
825
- are supported (regression). *Sergey Nartimov*
757
+ *Eric Hankins*
826
758
 
827
- * Fix possible race condition when two threads try to define attribute
828
- methods for the same class. *Jon Leighton*
829
759
 
760
+ ## Rails 4.0.3 (February 18, 2014) ##
830
761
 
831
- ## Rails 3.2.0 (January 20, 2012) ##
762
+ * Correctly escape PostgreSQL arrays.
832
763
 
833
- * Added a `with_lock` method to ActiveRecord objects, which starts
834
- a transaction, locks the object (pessimistically) and yields to the block.
835
- The method takes one (optional) parameter and passes it to `lock!`.
764
+ Fixes: CVE-2014-0080
836
765
 
837
- Before:
838
766
 
839
- class Order < ActiveRecord::Base
840
- def cancel!
841
- transaction do
842
- lock!
843
- # ... cancelling logic
844
- end
845
- end
846
- end
767
+ ## Rails 4.0.2 (December 02, 2013) ##
847
768
 
848
- After:
769
+ *No changes*
849
770
 
850
- class Order < ActiveRecord::Base
851
- def cancel!
852
- with_lock do
853
- # ... cancelling logic
854
- end
855
- end
856
- end
857
771
 
858
- *Olek Janiszewski*
772
+ ## Rails 4.0.1 (November 01, 2013) ##
859
773
 
860
- * 'on' and 'ON' boolean columns values are type casted to true
861
- *Santiago Pastorino*
774
+ * `NullRelation#pluck` takes a list of columns
862
775
 
863
- * Added ability to run migrations only for given scope, which allows
864
- to run migrations only from one engine (for example to revert changes
865
- from engine that you want to remove).
776
+ The method signature in `NullRelation` was updated to mimic that in
777
+ `Calculations`.
866
778
 
867
- Example:
868
- rake db:migrate SCOPE=blog
779
+ *Derek Prior*
780
+
781
+ * `scope_chain` should not be mutated for other reflections.
782
+
783
+ Currently `scope_chain` uses same array for building different
784
+ `scope_chain` for different associations. During processing
785
+ these arrays are sometimes mutated and because of in-place
786
+ mutation the changed `scope_chain` impacts other reflections.
787
+
788
+ Fix is to dup the value before adding to the `scope_chain`.
789
+
790
+ Fixes #3882.
791
+
792
+ *Neeraj Singh*
793
+
794
+ * Prevent the inversed association from being reloaded on save.
795
+
796
+ Fixes #9499.
797
+
798
+ *Dmitry Polushkin*
799
+
800
+ * `Relation#order` quotes the column name if you pass a `Symbol`.
801
+ Fixes #11870.
802
+
803
+ Example:
804
+
805
+ # Before
806
+ Post.order(:id).to_sql == '... ORDER BY "posts".id ASC'
807
+
808
+ # After
809
+ Post.order(:id).to_sql == '... ORDER BY "posts"."id" ASC'
810
+
811
+ *Yves Senn*
812
+
813
+ * Generate subquery for `Relation` if it passed as array condition for `where`
814
+ method.
815
+
816
+ Example:
817
+
818
+ # Before
819
+ Blog.where('id in (?)', Blog.where(id: 1))
820
+ # => SELECT "blogs".* FROM "blogs" WHERE "blogs"."id" = 1
821
+ # => SELECT "blogs".* FROM "blogs" WHERE (id IN (1))
822
+
823
+ # After
824
+ Blog.where('id in (?)', Blog.where(id: 1).select(:id))
825
+ # => SELECT "blogs".* FROM "blogs"
826
+ # WHERE "blogs"."id" IN (SELECT "blogs"."id" FROM "blogs" WHERE "blogs"."id" = 1)
827
+
828
+ Fixes #12415.
829
+
830
+ *Paul Nikitochkin*
831
+
832
+ * For missed association exception message
833
+ which is raised in `ActiveRecord::Associations::Preloader` class
834
+ added owner record class name in order to simplify to find problem code.
835
+
836
+ *Paul Nikitochkin*
837
+
838
+ * Fixes bug when using includes combined with select, the select statement was overwritten.
839
+
840
+ Fixes #11773.
841
+
842
+ *Edo Balvers*
843
+
844
+ * Objects instantiated using a null relationship will now retain the
845
+ attributes of the where clause.
846
+
847
+ Fixes #11676, #11675, #11376.
848
+
849
+ *Paul Nikitochkin*, *Peter Brown*, *Nthalk*
850
+
851
+ * Fixed `ActiveRecord::Associations::CollectionAssociation#find`
852
+ when using `has_many` association with `:inverse_of` and finding an array of one element,
853
+ it should return an array of one element too.
854
+
855
+ *arthurnn*
856
+
857
+ * Callbacks on has_many should access the in memory parent if a inverse_of is set.
858
+
859
+ *arthurnn*
860
+
861
+ * Migration dump UUID default functions to schema.rb.
862
+
863
+ Fixes #10751.
864
+
865
+ *kennyj*
866
+
867
+ * Fixed a bug in `ActiveRecord::Associations::CollectionAssociation#find_by_scan`
868
+ when using `has_many` association with `:inverse_of` option and UUID primary key.
869
+
870
+ Fixes #10450.
871
+
872
+ *kennyj*
873
+
874
+ * Fix: joins association, with defined in the scope block constraints by using several
875
+ where constraints and at least of them is not `Arel::Nodes::Equality`,
876
+ generates invalid SQL expression.
877
+
878
+ Fixes: #11963
879
+
880
+ *Paul Nikitochkin*
881
+
882
+ * Make possible to run SQLite rake tasks without the `Rails` constant defined.
883
+
884
+ *Damien Mathieu*
885
+
886
+ * Allow Relation#from to accept other relations with bind values.
887
+
888
+ *Ryan Wallace*
889
+
890
+ * Make `find_in_batches` and `find_each` work without a logger.
891
+
892
+ *Dmitry Polushkin*
893
+
894
+ * Fix inserts with prepared statements disabled.
895
+
896
+ Fixes #12023.
897
+
898
+ *Rafael Mendonça França*
899
+
900
+ * Setting a has_one association on a new record no longer causes an empty
901
+ transaction.
902
+
903
+ *Dylan Thacker-Smith*
904
+
905
+ * Fix `AR::Relation#merge` sometimes failing to preserve `readonly(false)` flag.
906
+
907
+ *thedarkone*
908
+
909
+ * PostgreSQL adapter recognizes negative money values formatted with
910
+ parentheses (eg. `($1.25) # => -1.25`)).
911
+ Fixes #11899.
912
+
913
+ * Yves Senn*
914
+
915
+ * Do not load all child records for inverse case.
916
+
917
+ currently `post.comments.find(Comment.first.id)` would load all
918
+ comments for the given post to set the inverse association.
919
+
920
+ This has a huge performance penalty. Because if post has 100k
921
+ records and all these 100k records would be loaded in memory
922
+ even though the comment id was supplied.
923
+
924
+ Fix is to use in-memory records only if loaded? is true. Otherwise
925
+ load the records using full sql.
926
+
927
+ Fixes #10509.
928
+
929
+ *Neeraj Singh*
930
+
931
+ * `ActiveRecord::FinderMethods#exists?` returns `true`/`false` in all cases.
932
+
933
+ *Xavier Noria*
934
+
935
+ * Load fixtures from linked folders.
936
+
937
+ *Kassio Borges*
938
+
939
+ * Create a directory for sqlite3 file if not present on the system.
940
+
941
+ *Richard Schneeman*
942
+
943
+ * Removed redundant override of `xml` column definition for PG,
944
+ in order to use `xml` column type instead of `text`.
945
+
946
+ *Paul Nikitochkin*, *Michael Nikitochkin*
947
+
948
+ * Revert `ActiveRecord::Relation#order` change that make new order
949
+ prepend the old one.
950
+
951
+ Before:
952
+
953
+ User.order("name asc").order("created_at desc")
954
+ # SELECT * FROM users ORDER BY created_at desc, name asc
955
+
956
+ After:
957
+
958
+ User.order("name asc").order("created_at desc")
959
+ # SELECT * FROM users ORDER BY name asc, created_at desc
960
+
961
+ This also affects order defined in `default_scope` or any kind of associations.
962
+
963
+ *Rafael Mendonça França*
964
+
965
+ * When using optimistic locking, `update` was not passing the column to `quote_value`
966
+ to allow the connection adapter to properly determine how to quote the value. This was
967
+ affecting certain databases that use specific column types.
968
+
969
+ Fixes #6763.
970
+
971
+ *Alfred Wong*
972
+
973
+ * `change_column` for PostgreSQL adapter respects the `:array` option.
974
+
975
+ *Yves Senn*
976
+
977
+ * Fixes bug introduced by #3329. Now, when autosaving associations,
978
+ deletions happen before inserts and saves. This prevents a
979
+ 'duplicate unique value' database error that would occur if a record being created had
980
+ the same value on a unique indexed field as that of a record being destroyed.
981
+
982
+ *Johnny Holton*
983
+
984
+ * Flatten merged join values before building the joins.
985
+
986
+ While joining values special treatment is given to string values.
987
+ By flattening the array it ensures that string values are detected
988
+ as strings and not arrays.
989
+
990
+ Fixes #10669.
991
+
992
+ *Neeraj Singh and iwiznia*
993
+
994
+ * Remove extra select and update queries on `save`/`touch`/`destroy` Active Record model
995
+ with belongs to reflection with option `touch: true`.
996
+
997
+ Fixes #11288.
998
+
999
+ *Paul Nikitochkin*
1000
+
1001
+ * Support array as root element in JSON fields.
1002
+
1003
+ *Alexey Noskov & Francesco Rodriguez*
1004
+
1005
+ * Apply default scope when joining associations. For example:
1006
+
1007
+ class Post < ActiveRecord::Base
1008
+ default_scope -> { where published: true }
1009
+ end
1010
+
1011
+ class Comment
1012
+ belongs_to :post
1013
+ end
1014
+
1015
+ When calling `Comment.joins(:post)`, we expect to receive only
1016
+ comments on published posts, since that is the default scope for
1017
+ posts.
1018
+
1019
+ Before this change, the default scope from `Post` was not applied,
1020
+ so we'd get comments on unpublished posts.
1021
+
1022
+ *Jon Leighton*
1023
+
1024
+ * `inspect` on Active Record model classes does not initiate a
1025
+ new connection. This means that calling `inspect`, when the
1026
+ database is missing, will no longer raise an exception.
1027
+
1028
+ Fixes #10936.
1029
+
1030
+ Example:
1031
+
1032
+ Author.inspect # => "Author(no database connection)"
1033
+
1034
+ *Yves Senn*
1035
+
1036
+ * Fix mysql2 adapter raises the correct exception when executing a query on a
1037
+ closed connection.
1038
+
1039
+ *Yves Senn*
1040
+
1041
+ * Fix the `:primary_key` option for `has_many` associations.
1042
+
1043
+ Fixes #10693.
1044
+
1045
+ *Yves Senn*
1046
+
1047
+ * Fix bug where tiny types are incorectly coerced as booleand when the length is more than 1.
1048
+
1049
+ Fixes #10620.
1050
+
1051
+ *Aaron Patterson*
1052
+
1053
+ * Also support extensions in PostgreSQL 9.1. This feature has been supported since 9.1.
1054
+
1055
+ *kennyj*
1056
+
1057
+ * Deprecate `ConnectionAdapters::SchemaStatements#distinct`,
1058
+ as it is no longer used by internals.
1059
+
1060
+ *Ben Woosley#
1061
+
1062
+ * Remove not needed bind variables. Port of commit #5082345.
1063
+
1064
+ Fixes #10958.
1065
+
1066
+ *Neeraj Singh*
1067
+
1068
+ * Confirm a record has not already been destroyed before decrementing counter cache.
1069
+
1070
+ *Ben Tucker*
1071
+
1072
+ * Fixed a bug in `ActiveRecord#sanitize_sql_hash_for_conditions` in which
1073
+ `self.class` is an argument to `PredicateBuilder#build_from_hash`
1074
+ causing `PredicateBuilder` to call non-existent method
1075
+ `Class#reflect_on_association`.
1076
+
1077
+ *Zach Ohlgren*
1078
+
1079
+ * While removing index if column option is missing then raise IrreversibleMigration exception.
1080
+
1081
+ Following code should raise `IrreversibleMigration`. But the code was
1082
+ failing since options is an array and not a hash.
1083
+
1084
+ def change
1085
+ change_table :users do |t|
1086
+ t.remove_index [:name, :email]
1087
+ end
1088
+ end
1089
+
1090
+ Fix was to check if the options is a Hash before operating on it.
1091
+
1092
+ Fixes #10419.
1093
+
1094
+ *Neeraj Singh*
1095
+
1096
+
1097
+ ## Rails 4.0.0 (June 25, 2013) ##
1098
+
1099
+ * Fix `add_column` with `array` option when using PostgreSQL. Fixes #10432
1100
+
1101
+ * Do not overwrite manually built records during one-to-one nested attribute assignment
1102
+
1103
+ For one-to-one nested associations, if you build the new (in-memory)
1104
+ child object yourself before assignment, then the NestedAttributes
1105
+ module will not overwrite it, e.g.:
1106
+
1107
+ class Member < ActiveRecord::Base
1108
+ has_one :avatar
1109
+ accepts_nested_attributes_for :avatar
1110
+
1111
+ def avatar
1112
+ super || build_avatar(width: 200)
1113
+ end
1114
+ end
1115
+
1116
+ member = Member.new
1117
+ member.avatar_attributes = {icon: 'sad'}
1118
+ member.avatar.width # => 200
1119
+
1120
+ *Olek Janiszewski*
1121
+
1122
+ * fixes bug introduced by #3329. Now, when autosaving associations,
1123
+ deletions happen before inserts and saves. This prevents a 'duplicate
1124
+ unique value' database error that would occur if a record being created had
1125
+ the same value on a unique indexed field as that of a record being destroyed.
1126
+
1127
+ *Adam Anderson*
1128
+
1129
+ * Fix pending migrations error when loading schema and `ActiveRecord::Base.table_name_prefix`
1130
+ is not blank.
1131
+
1132
+ Call `assume_migrated_upto_version` on connection to prevent it from first
1133
+ being picked up in `method_missing`.
1134
+
1135
+ In the base class, `Migration`, `method_missing` expects the argument to be a
1136
+ table name, and calls `proper_table_name` on the arguments before sending to
1137
+ `connection`. If `table_name_prefix` or `table_name_suffix` is used, the schema
1138
+ version changes to `prefix_version_suffix`, breaking `rake test:prepare`.
1139
+
1140
+ Fixes #10411.
1141
+
1142
+ *Kyle Stevens*
1143
+
1144
+ * Mute `psql` output when running rake db:schema:load.
1145
+
1146
+ *Godfrey Chan*
1147
+
1148
+ * Trigger a save on `has_one association=(associate)` when the associate contents have changed.
1149
+
1150
+ Fix #8856.
1151
+
1152
+ *Chris Thompson*
1153
+
1154
+ * Allow to use databases.rake tasks without having `Rails.application`.
869
1155
 
870
1156
  *Piotr Sarnacki*
871
1157
 
872
- * Migrations copied from engines are now scoped with engine's name,
873
- for example 01_create_posts.blog.rb. *Piotr Sarnacki*
1158
+ * Fix a `SystemStackError` problem when using time zone aware or serialized attributes.
1159
+ In current implementation, we reuse `column_types` argument when initiating an instance.
1160
+ If an instance has serialized or time zone aware attributes, `column_types` is
1161
+ wrapped multiple times in `decorate_columns` method. Thus the above error occurs.
1162
+
1163
+ *Dan Erikson & kennyj*
1164
+
1165
+ * Fix for a regression bug in which counter cache columns were not being updated
1166
+ when record was pushed into a has_many association. For example:
1167
+
1168
+ Post.first.comments << Comment.create
1169
+
1170
+ Fixes #3891.
1171
+
1172
+ *Matthew Robertson*
1173
+
1174
+ * If a model was instantiated from the database using `select`, `respond_to?`
1175
+ returns false for non-selected attributes. For example:
1176
+
1177
+ post = Post.select(:title).first
1178
+ post.respond_to?(:body) # => false
1179
+
1180
+ post = Post.select('title as post_title').first
1181
+ post.respond_to?(:title) # => false
1182
+
1183
+ Fixes #4208.
1184
+
1185
+ *Neeraj Singh*
1186
+
1187
+ * Run `rake migrate:down` & `rake migrate:up` in transaction if database supports.
1188
+
1189
+ *Alexander Bondarev*
1190
+
1191
+ * `0x` prefix must be added when assigning hexadecimal string into `bit` column in PostgreSQL.
1192
+
1193
+ *kennyj*
1194
+
1195
+ * Added Statement Cache to allow the caching of a single statement. The cache works by
1196
+ duping the relation returned from yielding a statement, which allows skipping the AST
1197
+ building phase for following executes. The cache returns results in array format.
1198
+
1199
+ Example:
1200
+
1201
+ cache = ActiveRecord::StatementCache.new do
1202
+ Book.where(name: "my book").limit(100)
1203
+ end
1204
+
1205
+ books = cache.execute
1206
+
1207
+ The solution attempts to get closer to the speed of `find_by_sql` but still maintaining
1208
+ the expressiveness of the Active Record queries.
1209
+
1210
+ *Olli Rissanen*
1211
+
1212
+ * Preserve context while merging relations with join information.
1213
+
1214
+ class Comment < ActiveRecord::Base
1215
+ belongs_to :post
1216
+ end
1217
+
1218
+ class Author < ActiveRecord::Base
1219
+ has_many :posts
1220
+ end
1221
+
1222
+ class Post < ActiveRecord::Base
1223
+ belongs_to :author
1224
+ has_many :comments
1225
+ end
1226
+
1227
+ `Comment.joins(:post).merge(Post.joins(:author).merge(Author.where(:name => "Joe Blogs"))).all`
1228
+ would fail with
1229
+ `ActiveRecord::ConfigurationError: Association named 'author' was not found on Comment`.
1230
+
1231
+ It is failing because `all` is being called on relation which looks like this after all
1232
+ the merging: `{:joins=>[:post, :author], :where=>[#<Arel::Nodes::Equality: ....}`. In this
1233
+ relation all the context that `Post` was joined with `Author` is lost and hence the error
1234
+ that `author` was not found on `Comment`.
1235
+
1236
+ The solution is to build `JoinAssociation` when two relations with join information are being
1237
+ merged. And later while building the Arel use the previously built `JoinAssociation` record
1238
+ in `JoinDependency#graft` to build the right from clause.
1239
+ Fixes #3002.
1240
+
1241
+ *Jared Armstrong and Neeraj Singh*
1242
+
1243
+ * `default_scopes?` is deprecated. Check for `default_scopes.empty?` instead.
1244
+
1245
+ *Agis Anastasopoulos*
1246
+
1247
+ * Default values for PostgreSQL bigint types now get parsed and dumped to the
1248
+ schema correctly.
1249
+
1250
+ *Erik Peterson*
1251
+
1252
+ * Fix associations with `:inverse_of` option when building association
1253
+ with a block. Inside the block the parent object was different then
1254
+ after the block.
1255
+
1256
+ Example:
1257
+
1258
+ parent.association.build do |child|
1259
+ child.parent.equal?(parent) # false
1260
+ end
1261
+
1262
+ # vs
1263
+
1264
+ child = parent.association.build
1265
+ child.parent.equal?(parent) # true
1266
+
1267
+ *Michal Cichra*
1268
+
1269
+ * `has_many` using `:through` now obeys the order clause mentioned in
1270
+ through association.
1271
+ Fixes #10016.
1272
+
1273
+ *Neeraj Singh*
1274
+
1275
+ * `belongs_to :touch` behavior now touches old association when
1276
+ transitioning to new association.
1277
+
1278
+ class Passenger < ActiveRecord::Base
1279
+ belongs_to :car, touch: true
1280
+ end
1281
+
1282
+ car_1 = Car.create
1283
+ car_2 = Car.create
1284
+
1285
+ passenger = Passenger.create car: car_1
1286
+
1287
+ passenger.car = car_2
1288
+ passenger.save
1289
+
1290
+ Previously only car_2 would be touched. Now both car_1 and car_2
1291
+ will be touched.
1292
+
1293
+ *Adam Gamble*
1294
+
1295
+ * Extract and deprecate Firebird / Sqlserver / Oracle database tasks, because
1296
+ These tasks should be supported by 3rd-party adapter.
1297
+
1298
+ *kennyj*
1299
+
1300
+ * Allow `ActiveRecord::Base.connection_handler` to have thread affinity and be
1301
+ settable, this effectively allows Active Record to be used in a multithreaded
1302
+ setup with multiple connections to multiple databases.
1303
+
1304
+ *Sam Saffron*
1305
+
1306
+ * `rename_column` preserves `auto_increment` in MySQL migrations.
1307
+ Fixes #3493.
1308
+
1309
+ *Vipul A M*
1310
+
1311
+ * PostgreSQL geometric type point is now supported by Active Record. Fixes #7324.
1312
+
1313
+ *Martin Schuerrer*
1314
+
1315
+ * Add support for concurrent indexing in PostgreSQL adapter via the
1316
+ `algorithm: :concurrently` option.
1317
+
1318
+ add_index(:people, :last_name, algorithm: :concurrently)
1319
+
1320
+ Also add support for MySQL index algorithms (`COPY`, `INPLACE`,
1321
+ `DEFAULT`) via the `:algorithm` option.
1322
+
1323
+ add_index(:people, :last_name, algorithm: :copy) # or :inplace/:default
1324
+
1325
+ *Dan McClain*
1326
+
1327
+ * Add support for fulltext and spatial indexes on MySQL tables with MyISAM database
1328
+ engine via the `type: 'FULLTEXT'` / `type: 'SPATIAL'` option.
1329
+
1330
+ add_index(:people, :last_name, type: 'FULLTEXT')
1331
+ add_index(:people, :last_name, type: 'SPATIAL')
1332
+
1333
+ *Ken Mazaika*
1334
+
1335
+ * Add an `add_index` override in PostgreSQL adapter and MySQL adapter
1336
+ to allow custom index type support.
1337
+ Fixes #6101.
1338
+
1339
+ add_index(:wikis, :body, :using => 'gin')
1340
+
1341
+ *Stefan Huber* and *Doabit*
1342
+
1343
+ * After extraction of mass-assignment attributes (which protects [id, type]
1344
+ by default) we can pass id to `update_attributes` and it will update
1345
+ another record because id will be used in where statement. We never have
1346
+ to change id in where statement because we try to set/replace fields for
1347
+ already loaded record but we have to try to set new id for that record.
1348
+
1349
+ *Dmitry Vorotilin*
1350
+
1351
+ * Models with multiple counter cache associations now update correctly on destroy.
1352
+ See #7706.
1353
+
1354
+ *Ian Young*
1355
+
1356
+ * If `:inverse_of` is true on an association, then when one calls `find()` on
1357
+ the association, Active Record will first look through the in-memory objects
1358
+ in the association for a particular id. Then, it will go to the DB if it
1359
+ is not found. This is accomplished by calling `find_by_scan` in
1360
+ collection associations whenever `options[:inverse_of]` is not nil.
1361
+ Fixes #9470.
1362
+
1363
+ *John Wang*
1364
+
1365
+ * `rake db:create` does not change permissions of the MySQL root user.
1366
+ Fixes #8079.
1367
+
1368
+ *Yves Senn*
1369
+
1370
+ * The length of the `version` column in the `schema_migrations` table
1371
+ created by the `mysql2` adapter is 191 if the encoding is "utf8mb4".
1372
+
1373
+ The "utf8" encoding in MySQL has support for a maximum of 3 bytes per character,
1374
+ and only contains characters from the BMP. The recently added
1375
+ [utf8mb4](http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8mb4.html)
1376
+ encoding extends the support to four bytes. As of this writing, said encoding
1377
+ is supported in the betas of the `mysql2` gem.
1378
+
1379
+ Setting the encoding to "utf8mb4" has
1380
+ [a few implications](http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-upgrading.html).
1381
+ This change addresses the max length for indexes, which is 191 instead of 255.
1382
+
1383
+ *Xavier Noria*
1384
+
1385
+ * Counter caches on associations will now stay valid when attributes are
1386
+ updated (not just when records are created or destroyed), for example,
1387
+ when calling `update_attributes`. The following code now works:
1388
+
1389
+ class Comment < ActiveRecord::Base
1390
+ belongs_to :post, counter_cache: true
1391
+ end
1392
+
1393
+ class Post < ActiveRecord::Base
1394
+ has_many :comments
1395
+ end
1396
+
1397
+ post = Post.create
1398
+ comment = Comment.create
1399
+
1400
+ post.comments << comment
1401
+ post.save.reload.comments_count # => 1
1402
+ comment.update_attributes(post_id: nil)
1403
+
1404
+ post.save.reload.comments_count # => 0
1405
+
1406
+ Updating the id of a `belongs_to` object with the id of a new object will
1407
+ also keep the count accurate.
1408
+
1409
+ *John Wang*
1410
+
1411
+ * Referencing join tables implicitly was deprecated. There is a
1412
+ possibility that these deprecation warnings are shown even if you
1413
+ don't make use of that feature. You can now disable the feature entirely.
1414
+ Fixes #9712.
1415
+
1416
+ Example:
1417
+
1418
+ # in your configuration
1419
+ config.active_record.disable_implicit_join_references = true
1420
+
1421
+ # or directly
1422
+ ActiveRecord::Base.disable_implicit_join_references = true
1423
+
1424
+ *Yves Senn*
1425
+
1426
+ * The `:distinct` option for `Relation#count` is deprecated. You
1427
+ should use `Relation#distinct` instead.
1428
+
1429
+ Example:
1430
+
1431
+ # Before
1432
+ Post.select(:author_name).count(distinct: true)
1433
+
1434
+ # After
1435
+ Post.select(:author_name).distinct.count
1436
+
1437
+ *Yves Senn*
1438
+
1439
+ * Rename `Relation#uniq` to `Relation#distinct`. `#uniq` is still
1440
+ available as an alias but we encourage to use `#distinct` instead.
1441
+ Also `Relation#uniq_value` is aliased to `Relation#distinct_value`,
1442
+ this is a temporary solution and you should migrate to `distinct_value`.
1443
+
1444
+ *Yves Senn*
1445
+
1446
+ * Fix quoting for sqlite migrations using `copy_table_contents` with binary
1447
+ columns.
1448
+
1449
+ These would fail with "SQLite3::SQLException: unrecognized token" because
1450
+ the column was not being passed to `quote` so the data was not quoted
1451
+ correctly.
1452
+
1453
+ *Matthew M. Boedicker*
1454
+
1455
+ * Promotes `change_column_null` to the migrations API. This macro sets/removes
1456
+ `NOT NULL` constraints, and accepts an optional argument to replace existing
1457
+ `NULL`s if needed. The adapters for SQLite, MySQL, PostgreSQL, and (at least)
1458
+ Oracle, already implement this method.
1459
+
1460
+ *Xavier Noria*
1461
+
1462
+ * Uniqueness validation allows you to pass `:conditions` to limit
1463
+ the constraint lookup.
1464
+
1465
+ Example:
1466
+
1467
+ validates_uniqueness_of :title, conditions: -> { where('approved = ?', true) }
1468
+
1469
+ *Mattias Pfeiffer + Yves Senn*
1470
+
1471
+ * `connection` is deprecated as an instance method.
1472
+ This allows end-users to have a `connection` method on their models
1473
+ without clashing with Active Record internals.
1474
+
1475
+ *Ben Moss*
1476
+
1477
+ * When copying migrations, preserve their magic comments and content encoding.
1478
+
1479
+ *OZAWA Sakuro*
1480
+
1481
+ * Fix `subclass_from_attrs` when `eager_load` is false. It cannot find
1482
+ subclass because all classes are loaded automatically when it needs.
1483
+
1484
+ *Dmitry Vorotilin*
1485
+
1486
+ * When `:name` option is provided to `remove_index`, use it if there is no
1487
+ index by the conventional name.
1488
+
1489
+ For example, previously if an index was removed like so
1490
+ `remove_index :values, column: :value, name: 'a_different_name'`
1491
+ the generated SQL would not contain the specified index name,
1492
+ and hence the migration would fail.
1493
+ Fixes #8858.
1494
+
1495
+ *Ezekiel Smithburg*
1496
+
1497
+ * Created block to by-pass the prepared statement bindings.
1498
+ This will allow to compose fragments of large SQL statements to
1499
+ avoid multiple round-trips between Ruby and the DB.
1500
+
1501
+ Example:
1502
+
1503
+ sql = Post.connection.unprepared_statement do
1504
+ Post.first.comments.to_sql
1505
+ end
1506
+
1507
+ *Cédric Fabianski*
1508
+
1509
+ * Change the semantics of combining scopes to be the same as combining
1510
+ class methods which return scopes. For example:
1511
+
1512
+ class User < ActiveRecord::Base
1513
+ scope :active, -> { where state: 'active' }
1514
+ scope :inactive, -> { where state: 'inactive' }
1515
+ end
1516
+
1517
+ class Post < ActiveRecord::Base
1518
+ def self.active
1519
+ where state: 'active'
1520
+ end
1521
+
1522
+ def self.inactive
1523
+ where state: 'inactive'
1524
+ end
1525
+ end
1526
+
1527
+ ### BEFORE ###
1528
+
1529
+ User.where(state: 'active').where(state: 'inactive')
1530
+ # => SELECT * FROM users WHERE state = 'active' AND state = 'inactive'
1531
+
1532
+ User.active.inactive
1533
+ # => SELECT * FROM users WHERE state = 'inactive'
1534
+
1535
+ Post.active.inactive
1536
+ # => SELECT * FROM posts WHERE state = 'active' AND state = 'inactive'
1537
+
1538
+ ### AFTER ###
1539
+
1540
+ User.active.inactive
1541
+ # => SELECT * FROM posts WHERE state = 'active' AND state = 'inactive'
1542
+
1543
+ Before this change, invoking a scope would merge it into the current
1544
+ scope and return the result. `Relation#merge` applies "last where
1545
+ wins" logic to de-duplicate the conditions, but this lead to
1546
+ confusing and inconsistent behaviour. This fixes that.
1547
+
1548
+ If you really do want the "last where wins" logic, you can opt-in to
1549
+ it like so:
1550
+
1551
+ User.active.merge(User.inactive)
1552
+
1553
+ Fixes #7365.
1554
+
1555
+ *Neeraj Singh* and *Jon Leighton*
1556
+
1557
+ * Expand `#cache_key` to consult all relevant updated timestamps.
1558
+
1559
+ Previously only `updated_at` column was checked, now it will
1560
+ consult other columns that received updated timestamps on save,
1561
+ such as `updated_on`. When multiple columns are present it will
1562
+ use the most recent timestamp.
1563
+ Fixes #9033.
1564
+
1565
+ *Brendon Murphy*
1566
+
1567
+ * Throw `NotImplementedError` when trying to instantiate `ActiveRecord::Base` or an abstract class.
1568
+
1569
+ *Aaron Weiner*
1570
+
1571
+ * Warn when `rake db:structure:dump` with a MySQL database and
1572
+ `mysqldump` is not in the PATH or fails.
1573
+ Fixes #9518.
1574
+
1575
+ *Yves Senn*
1576
+
1577
+ * Remove `connection#structure_dump`, which is no longer used. *Yves Senn*
1578
+
1579
+ * Make it possible to execute migrations without a transaction even
1580
+ if the database adapter supports DDL transactions.
1581
+ Fixes #9483.
1582
+
1583
+ Example:
1584
+
1585
+ class ChangeEnum < ActiveRecord::Migration
1586
+ disable_ddl_transaction!
1587
+
1588
+ def up
1589
+ execute "ALTER TYPE model_size ADD VALUE 'new_value'"
1590
+ end
1591
+ end
1592
+
1593
+ *Yves Senn*
1594
+
1595
+ * Assigning "0.0" to a nullable numeric column does not make it dirty.
1596
+ Fixes #9034.
1597
+
1598
+ Example:
1599
+
1600
+ product = Product.create price: 0.0
1601
+ product.price = '0.0'
1602
+ product.changed? # => false (this used to return true)
1603
+ product.changes # => {} (this used to return { price: [0.0, 0.0] })
1604
+
1605
+ *Yves Senn*
1606
+
1607
+ * Added functionality to unscope relations in a relations chain. For
1608
+ instance, if you are passed in a chain of relations as follows:
1609
+
1610
+ User.where(name: "John").order('id DESC')
1611
+
1612
+ but you want to get rid of order, then this feature allows you to do:
1613
+
1614
+ User.where(name: "John").order('id DESC').unscope(:order)
1615
+ == User.where(name: "John")
1616
+
1617
+ The .unscope() function is more general than the .except() method because
1618
+ .except() only works on the relation it is acting on. However, .unscope()
1619
+ works for any relation in the entire relation chain.
1620
+
1621
+ *John Wang*
1622
+
1623
+ * PostgreSQL timestamp with time zone (timestamptz) datatype now returns a
1624
+ ActiveSupport::TimeWithZone instance instead of a string
1625
+
1626
+ *Troy Kruthoff*
1627
+
1628
+ * The `#append` method for collection associations behaves like`<<`.
1629
+ `#prepend` is not defined and `<<` or `#append` should be used.
1630
+ Fixes #7364.
1631
+
1632
+ *Yves Senn*
1633
+
1634
+ * Added support for creating a table via Rails migration generator.
1635
+ For example,
1636
+
1637
+ rails g migration create_books title:string content:text
1638
+
1639
+ will generate a migration that creates a table called books with
1640
+ the listed attributes, without creating a model.
1641
+
1642
+ *Sammy Larbi*
1643
+
1644
+ * Fix bug that raises the wrong exception when the exception handled by PostgreSQL adapter
1645
+ doesn't respond to `#result`.
1646
+ Fixes #8617.
1647
+
1648
+ *kennyj*
1649
+
1650
+ * Support PostgreSQL specific column types when using `change_table`.
1651
+ Fixes #9480.
1652
+
1653
+ Example:
1654
+
1655
+ change_table :authors do |t|
1656
+ t.hstore :books
1657
+ t.json :metadata
1658
+ end
1659
+
1660
+ *Yves Senn*
1661
+
1662
+ * Revert 408227d9c5ed7d, 'quote numeric'. This introduced some regressions.
1663
+
1664
+ *Steve Klabnik*
1665
+
1666
+ * Fix calculation of `db_runtime` property in
1667
+ `ActiveRecord::Railties::ControllerRuntime#cleanup_view_runtime`.
1668
+ Previously, after raising `ActionView::MissingTemplate`, `db_runtime` was
1669
+ not populated.
1670
+ Fixes #9215.
1671
+
1672
+ *Igor Fedoronchuk*
1673
+
1674
+ * Do not try to touch invalid (and thus not persisted) parent record
1675
+ for a `belongs_to :parent, touch: true` association
1676
+
1677
+ *Olek Janiszewski*
1678
+
1679
+ * Fix when performing an ordered join query. The bug only
1680
+ affected queries where the order was given with a symbol.
1681
+ Fixes #9275.
1682
+
1683
+ Example:
1684
+
1685
+ # This will expand the order :name to "authors".name.
1686
+ Author.joins(:books).where('books.published = 1').order(:name)
1687
+
1688
+ * Fix overriding of attributes by `default_scope` on `ActiveRecord::Base#dup`.
1689
+
1690
+ *Hiroshige UMINO*
1691
+
1692
+ * Update queries now use prepared statements.
1693
+
1694
+ *Olli Rissanen*
1695
+
1696
+ * Fixing issue #8345. Now throwing an error when one attempts to touch a
1697
+ new object that has not yet been persisted. For instance:
1698
+
1699
+ Example:
1700
+
1701
+ ball = Ball.new
1702
+ ball.touch :updated_at # => raises error
1703
+
1704
+ It is not until the ball object has been persisted that it can be touched.
1705
+ This follows the behavior of update_column.
1706
+
1707
+ *John Wang*
1708
+
1709
+ * Preloading ordered `has_many :through` associations no longer applies
1710
+ invalid ordering to the `:through` association.
1711
+ Fixes #8663.
1712
+
1713
+ *Yves Senn*
1714
+
1715
+ * The auto explain feature has been removed. This feature was
1716
+ activated by configuring `config.active_record.auto_explain_threshold_in_seconds`.
1717
+ The configuration option was deprecated and has no more effect.
1718
+
1719
+ You can still use `ActiveRecord::Relation#explain` to see the EXPLAIN output for
1720
+ any given relation.
1721
+
1722
+ *Yves Senn*
1723
+
1724
+ * The `:on` option for `after_commit` and `after_rollback` now
1725
+ accepts an Array of actions.
1726
+ Fixes #988.
1727
+
1728
+ Example:
1729
+
1730
+ after_commit :update_cache on: [:create, :update]
1731
+
1732
+ *Yves Senn*
1733
+
1734
+ * Rename related indexes on `rename_table` and `rename_column`. This
1735
+ does not affect indexes with custom names.
1736
+
1737
+ *Yves Senn*
1738
+
1739
+ * Prevent the creation of indices with too long names, which cause
1740
+ internal operations to fail (sqlite3 adapter only). The method
1741
+ `allowed_index_name_length` defines the length limit enforced by
1742
+ rails. It's value defaults to `index_name_length` but can vary per adapter.
1743
+ Fixes #8264.
1744
+
1745
+ *Yves Senn*
1746
+
1747
+ * Fixing issue #776.
1748
+
1749
+ Memory bloat in transactions is handled by having the transaction hold only
1750
+ the AR objects which it absolutely needs to know about. These are the AR
1751
+ objects with callbacks (they need to be updated as soon as something in the
1752
+ transaction occurs).
1753
+
1754
+ All other AR objects can be updated lazily by keeping a reference to a
1755
+ TransactionState object. If an AR object gets inside a transaction, then
1756
+ the transaction will add its TransactionState to the AR object. When the
1757
+ user makes a call to some attribute on an AR object (which has no
1758
+ callbacks) associated with a transaction, the AR object will call the
1759
+ sync_with_transaction_state method and make sure it is up to date with the
1760
+ transaction. After it has synced with the transaction state, the AR object
1761
+ will return the attribute that was requested.
1762
+
1763
+ Most of the logic in the changes are used to handle multiple transactions,
1764
+ in which case the AR object has to recursively follow parent pointers of
1765
+ TransactionState objects.
1766
+
1767
+ *John Wang*
1768
+
1769
+ * Descriptive error message when the necessary AR adapter gem was not found.
1770
+ Fixes #7313.
1771
+
1772
+ *Yves Senn*
1773
+
1774
+ * Active Record now raises an error when blank arguments are passed to query
1775
+ methods for which blank arguments do not make sense.
1776
+
1777
+ Example:
1778
+
1779
+ Post.includes() # => raises error
1780
+
1781
+ *John Wang*
1782
+
1783
+ * Simplified type casting code for timezone aware attributes to use the
1784
+ `in_time_zone` method if it is available. This introduces a subtle change
1785
+ of behavior when using `Date` instances as they are directly converted to
1786
+ `ActiveSupport::TimeWithZone` instances without first being converted to
1787
+ `Time` instances. For example:
1788
+
1789
+ # Rails 3.2 behavior
1790
+ >> Date.today.to_time.in_time_zone
1791
+ => Wed, 13 Feb 2013 07:00:00 UTC +00:00
1792
+
1793
+ # Rails 4.0 behavior
1794
+ >> Date.today.in_time_zone
1795
+ => Wed, 13 Feb 2013 00:00:00 UTC +00:00
1796
+
1797
+ On the plus side it now behaves the same whether you pass a `String` date
1798
+ or an actual `Date` instance. For example:
1799
+
1800
+ # Rails 3.2 behavior
1801
+ >> Date.civil(2013, 2, 13).to_time.in_time_zone
1802
+ => Wed, 13 Feb 2013 07:00:00 UTC +00:00
1803
+ >> Time.zone.parse("2013-02-13")
1804
+ => Wed, 13 Feb 2013 00:00:00 UTC +00:00
1805
+
1806
+ # Rails 4.0 behavior
1807
+ >> Date.civil(2013, 2, 13).in_time_zone
1808
+ => Wed, 13 Feb 2013 00:00:00 UTC +00:00
1809
+ >> "2013-02-13".in_time_zone
1810
+ => Wed, 13 Feb 2013 00:00:00 UTC +00:00
1811
+
1812
+ If you need the old behavior you can convert the dates to times manually.
1813
+ For example:
1814
+
1815
+ >> Post.new(created_at: Date.today).created_at
1816
+ => Wed, 13 Feb 2013 00:00:00 UTC +00:00
1817
+
1818
+ >> Post.new(created_at: Date.today.to_time).created_at
1819
+ => Wed, 13 Feb 2013 07:00:00 UTC +00:00
1820
+
1821
+ *Andrew White*
1822
+
1823
+ * Preloading `has_many :through` associations with conditions won't
1824
+ cache the `:through` association. This will prevent invalid
1825
+ subsets to be cached.
1826
+ Fixes #8423.
1827
+
1828
+ Example:
1829
+
1830
+ class User
1831
+ has_many :posts
1832
+ has_many :recent_comments, -> { where('created_at > ?', 1.week.ago) }, :through => :posts
1833
+ end
1834
+
1835
+ a_user = User.includes(:recent_comments).first
1836
+
1837
+ # This is preloaded.
1838
+ a_user.recent_comments
1839
+
1840
+ # This is not preloaded, fetched now.
1841
+ a_user.posts
1842
+
1843
+ *Yves Senn*
1844
+
1845
+ * Don't run `after_commit` callbacks when creating through an association
1846
+ if saving the record fails.
1847
+
1848
+ *James Miller*
1849
+
1850
+ * Allow store accessors to be overridden like other attribute methods, e.g.:
1851
+
1852
+ class User < ActiveRecord::Base
1853
+ store :settings, accessors: [ :color, :homepage ], coder: JSON
1854
+
1855
+ def color
1856
+ super || 'red'
1857
+ end
1858
+ end
1859
+
1860
+ *Sergey Nartimov*
1861
+
1862
+ * Quote numeric values being compared to non-numeric columns. Otherwise,
1863
+ in some database, the string column values will be coerced to a numeric
1864
+ allowing 0, 0.0 or false to match any string starting with a non-digit.
1865
+
1866
+ Example:
1867
+
1868
+ App.where(apikey: 0) # => SELECT * FROM users WHERE apikey = '0'
1869
+
1870
+ *Dylan Smith*
1871
+
1872
+ * Schema dumper supports dumping the enabled database extensions to `schema.rb`
1873
+ (currently only supported by PostgreSQL).
1874
+
1875
+ *Justin George*
1876
+
1877
+ * The database adapters now converts the options passed thought `DATABASE_URL`
1878
+ environment variable to the proper Ruby types before using. For example, SQLite requires
1879
+ that the timeout value is an integer, and PostgreSQL requires that the
1880
+ prepared_statements option is a boolean. These now work as expected:
1881
+
1882
+ Example:
1883
+
1884
+ DATABASE_URL=sqlite3://localhost/test_db?timeout=500
1885
+ DATABASE_URL=postgresql://localhost/test_db?prepared_statements=false
1886
+
1887
+ *Aaron Stone + Rafael Mendonça França*
1888
+
1889
+ * `Relation#merge` now only overwrites where values on the LHS of the
1890
+ merge. Consider:
1891
+
1892
+ left = Person.where(age: [13, 14, 15])
1893
+ right = Person.where(age: [13, 14]).where(age: [14, 15])
1894
+
1895
+ `left` results in the following SQL:
1896
+
1897
+ WHERE age IN (13, 14, 15)
1898
+
1899
+ `right` results in the following SQL:
1900
+
1901
+ WHERE age IN (13, 14) AND age IN (14, 15)
1902
+
1903
+ Previously, `left.merge(right)` would result in all but the last
1904
+ condition being removed:
1905
+
1906
+ WHERE age IN (14, 15)
1907
+
1908
+ Now it results in the LHS condition(s) for `age` being removed, but
1909
+ the RHS remains as it is:
1910
+
1911
+ WHERE age IN (13, 14) AND age IN (14, 15)
1912
+
1913
+ *Jon Leighton*
1914
+
1915
+ * Fix handling of dirty time zone aware attributes
1916
+
1917
+ Previously, when `time_zone_aware_attributes` were enabled, after
1918
+ changing a datetime or timestamp attribute and then changing it back
1919
+ to the original value, `changed_attributes` still tracked the
1920
+ attribute as changed. This caused `[attribute]_changed?` and
1921
+ `changed?` methods to return true incorrectly.
1922
+
1923
+ Example:
1924
+
1925
+ in_time_zone 'Paris' do
1926
+ order = Order.new
1927
+ original_time = Time.local(2012, 10, 10)
1928
+ order.shipped_at = original_time
1929
+ order.save
1930
+ order.changed? # => false
1931
+
1932
+ # changing value
1933
+ order.shipped_at = Time.local(2013, 1, 1)
1934
+ order.changed? # => true
1935
+
1936
+ # reverting to original value
1937
+ order.shipped_at = original_time
1938
+ order.changed? # => false, used to return true
1939
+ end
1940
+
1941
+ *Lilibeth De La Cruz*
1942
+
1943
+ * When `#count` is used in conjunction with `#uniq` we perform `count(:distinct => true)`.
1944
+ Fixes #6865.
1945
+
1946
+ Example:
1947
+
1948
+ relation.uniq.count # => SELECT COUNT(DISTINCT *)
1949
+
1950
+ *Yves Senn + Kaspar Schiess*
1951
+
1952
+ * PostgreSQL ranges type support. Includes: int4range, int8range,
1953
+ numrange, tsrange, tstzrange, daterange
1954
+
1955
+ Ranges can be created with inclusive and exclusive bounds.
1956
+
1957
+ Example:
1958
+
1959
+ create_table :Room do |t|
1960
+ t.daterange :availability
1961
+ end
1962
+
1963
+ Room.create(availability: (Date.today..Float::INFINITY))
1964
+ Room.first.availability # => Wed, 19 Sep 2012..Infinity
1965
+
1966
+ One thing to note: Range class does not support exclusive lower
1967
+ bound.
1968
+
1969
+ *Alexander Grebennik*
1970
+
1971
+ * Added a state instance variable to each transaction. Will allow other objects
1972
+ to know whether a transaction has been committed or rolled back.
1973
+
1974
+ *John Wang*
1975
+
1976
+ * Collection associations `#empty?` always respects built records.
1977
+ Fixes #8879.
1978
+
1979
+ Example:
1980
+
1981
+ widget = Widget.new
1982
+ widget.things.build
1983
+ widget.things.empty? # => false
1984
+
1985
+ *Yves Senn*
1986
+
1987
+ * Support for PostgreSQL's `ltree` data type.
1988
+
1989
+ *Rob Worley*
1990
+
1991
+ * Fix undefined method `to_i` when calling `new` on a scope that uses an
1992
+ Array; Fix FloatDomainError when setting integer column to NaN.
1993
+ Fixes #8718, #8734, #8757.
1994
+
1995
+ *Jason Stirk + Tristan Harward*
1996
+
1997
+ * Rename `update_attributes` to `update`, keep `update_attributes` as an alias for `update` method.
1998
+ This is a soft-deprecation for `update_attributes`, although it will still work without any
1999
+ deprecation message in 4.0 is recommended to start using `update` since `update_attributes` will be
2000
+ deprecated and removed in future versions of Rails.
2001
+
2002
+ *Amparo Luna + Guillermo Iguaran*
2003
+
2004
+ * `after_commit` and `after_rollback` now validate the `:on` option and raise an `ArgumentError`
2005
+ if it is not one of `:create`, `:destroy` or `:update`
2006
+
2007
+ *Pascal Friederich*
2008
+
2009
+ * Improve ways to write `change` migrations, making the old `up` & `down` methods no longer necessary.
2010
+
2011
+ * The methods `drop_table` and `remove_column` are now reversible, as long as the necessary information is given.
2012
+ The method `remove_column` used to accept multiple column names; instead use `remove_columns` (which is not reversible).
2013
+ The method `change_table` is also reversible, as long as its block doesn't call `remove`, `change` or `change_default`
2014
+
2015
+ * New method `reversible` makes it possible to specify code to be run when migrating up or down.
2016
+ See the [Guide on Migration](https://github.com/rails/rails/blob/master/guides/source/migrations.md#using-the-reversible-method)
2017
+
2018
+ * New method `revert` will revert a whole migration or the given block.
2019
+ If migrating down, the given migration / block is run normally.
2020
+ See the [Guide on Migration](https://github.com/rails/rails/blob/master/guides/source/migrations.md#reverting-previous-migrations)
2021
+
2022
+ Attempting to revert the methods `execute`, `remove_columns` and `change_column` will now
2023
+ raise an `IrreversibleMigration` instead of actually executing them without any output.
2024
+
2025
+ *Marc-André Lafortune*
2026
+
2027
+ * Serialized attributes can be serialized in integer columns.
2028
+ Fixes #8575.
2029
+
2030
+ *Rafael Mendonça França*
2031
+
2032
+ * Keep index names when using `alter_table` with sqlite3.
2033
+ Fixes #3489.
2034
+
2035
+ *Yves Senn*
2036
+
2037
+ * Add ability for PostgreSQL adapter to disable user triggers in `disable_referential_integrity`.
2038
+ Fixes #5523.
2039
+
2040
+ *Gary S. Weaver*
2041
+
2042
+ * Added support for `validates_uniqueness_of` in PostgreSQL array columns.
2043
+ Fixes #8075.
2044
+
2045
+ *Pedro Padron*
2046
+
2047
+ * Allow int4range and int8range columns to be created in PostgreSQL and properly convert to/from database.
2048
+
2049
+ *Alexey Vasiliev aka leopard*
2050
+
2051
+ * Do not log the binding values for binary columns.
2052
+
2053
+ *Matthew M. Boedicker*
2054
+
2055
+ * Fix counter cache columns not updated when replacing `has_many :through`
2056
+ associations.
2057
+
2058
+ *Matthew Robertson*
2059
+
2060
+ * Recognize migrations placed in directories containing numbers and 'rb'.
2061
+ Fixes #8492.
2062
+
2063
+ *Yves Senn*
2064
+
2065
+ * Add `ActiveRecord::Base.cache_timestamp_format` class attribute to control
2066
+ the format of the timestamp value in the cache key. Defaults to `:nsec`.
2067
+ Fixes #8195.
2068
+
2069
+ *Rafael Mendonça França*
2070
+
2071
+ * Session variables can be set for the `mysql`, `mysql2`, and `postgresql` adapters
2072
+ in the `variables: <hash>` parameter in `config/database.yml`. The key-value pairs of this
2073
+ hash will be sent in a `SET key = value` query on new database connections. See also:
2074
+ http://dev.mysql.com/doc/refman/5.0/en/set-statement.html
2075
+ http://www.postgresql.org/docs/8.3/static/sql-set.html
2076
+
2077
+ *Aaron Stone*
2078
+
2079
+ * Allow setting of all libpq connection parameters through the PostgreSQL adapter. See also:
2080
+ http://www.postgresql.org/docs/9.2/static/libpq-connect.html#LIBPQ-PARAMKEYWORDS
2081
+
2082
+ *Lars Kanis*
2083
+
2084
+ * Allow `Relation#where` with no arguments to be chained with new `not` query method.
2085
+
2086
+ Example:
2087
+
2088
+ Developer.where.not(name: 'Aaron')
2089
+
2090
+ *Akira Matsuda*
2091
+
2092
+ * Unscope `update_column(s)` query to ignore default scope.
2093
+
2094
+ When applying `default_scope` to a class with a where clause, using
2095
+ `update_column(s)` could generate a query that would not properly update
2096
+ the record due to the where clause from the `default_scope` being applied
2097
+ to the update query.
2098
+
2099
+ class User < ActiveRecord::Base
2100
+ default_scope -> { where(active: true) }
2101
+ end
2102
+
2103
+ user = User.first
2104
+ user.active = false
2105
+ user.save!
2106
+
2107
+ user.update_column(:active, true) # => false
2108
+
2109
+ In this situation we want to skip the default_scope clause and just
2110
+ update the record based on the primary key. With this change:
2111
+
2112
+ user.update_column(:active, true) # => true
2113
+
2114
+ Fixes #8436.
2115
+
2116
+ *Carlos Antonio da Silva*
2117
+
2118
+ * SQLite adapter no longer corrupts binary data if the data contains `%00`.
2119
+
2120
+ *Chris Feist*
2121
+
2122
+ * Fix performance problem with `primary_key` method in PostgreSQL adapter when having many schemas.
2123
+ Uses `pg_constraint` table instead of `pg_depend` table which has many records in general.
2124
+ Fixes #8414.
2125
+
2126
+ *kennyj*
2127
+
2128
+ * Do not instantiate intermediate Active Record objects when eager loading.
2129
+ These records caused `after_find` to run more than expected.
2130
+ Fixes #3313.
2131
+
2132
+ *Yves Senn*
2133
+
2134
+ * Add STI support to init and building associations.
2135
+ Allows you to do `BaseClass.new(type: "SubClass")` as well as
2136
+ `parent.children.build(type: "SubClass")` or `parent.build_child`
2137
+ to initialize an STI subclass. Ensures that the class name is a
2138
+ valid class and that it is in the ancestors of the super class
2139
+ that the association is expecting.
2140
+
2141
+ *Jason Rush*
2142
+
2143
+ * Observers was extracted from Active Record as `rails-observers` gem.
2144
+
2145
+ *Rafael Mendonça França*
2146
+
2147
+ * Ensure that associations take a symbol argument. *Steve Klabnik*
2148
+
2149
+ * Fix dirty attribute checks for `TimeZoneConversion` with nil and blank
2150
+ datetime attributes. Setting a nil datetime to a blank string should not
2151
+ result in a change being flagged.
2152
+ Fixes #8310.
2153
+
2154
+ *Alisdair McDiarmid*
2155
+
2156
+ * Prevent mass assignment to the type column of polymorphic associations when using `build`
2157
+ Fixes #8265.
2158
+
2159
+ *Yves Senn*
2160
+
2161
+ * Deprecate calling `Relation#sum` with a block. To perform a calculation over
2162
+ the array result of the relation, use `to_a.sum(&block)`.
2163
+
2164
+ *Carlos Antonio da Silva*
2165
+
2166
+ * Fix PostgreSQL adapter to handle BC timestamps correctly
2167
+
2168
+ HistoryEvent.create!(name: "something", occured_at: Date.new(0) - 5.years)
2169
+
2170
+ *Bogdan Gusiev*
2171
+
2172
+ * When running migrations on PostgreSQL, the `:limit` option for `binary` and `text` columns is silently dropped.
2173
+ Previously, these migrations caused sql exceptions, because PostgreSQL doesn't support limits on these types.
2174
+
2175
+ *Victor Costan*
2176
+
2177
+ * Don't change STI type when calling `ActiveRecord::Base#becomes`.
2178
+ Add `ActiveRecord::Base#becomes!` with the previous behavior.
2179
+
2180
+ See #3023 for more information.
2181
+
2182
+ *Thomas Hollstegge*
2183
+
2184
+ * `rename_index` can be used inside a `change_table` block.
2185
+
2186
+ change_table :accounts do |t|
2187
+ t.rename_index :user_id, :account_id
2188
+ end
2189
+
2190
+ *Jarek Radosz*
2191
+
2192
+ * `#pluck` can be used on a relation with `select` clause. Fix #7551
2193
+
2194
+ Example:
2195
+
2196
+ Topic.select([:approved, :id]).order(:id).pluck(:id)
2197
+
2198
+ *Yves Senn*
2199
+
2200
+ * Do not create useless database transaction when building `has_one` association.
2201
+
2202
+ Example:
2203
+
2204
+ User.has_one :profile
2205
+ User.new.build_profile
2206
+
2207
+ *Bogdan Gusiev*
2208
+
2209
+ * `:counter_cache` option for `has_many` associations to support custom named counter caches.
2210
+ Fixes #7993.
2211
+
2212
+ *Yves Senn*
2213
+
2214
+ * Deprecate the possibility to pass a string as third argument of `add_index`.
2215
+ Pass `unique: true` instead.
2216
+
2217
+ add_index(:users, :organization_id, unique: true)
2218
+
2219
+ *Rafael Mendonça França*
2220
+
2221
+ * Raise an `ArgumentError` when passing an invalid option to `add_index`.
2222
+
2223
+ *Rafael Mendonça França*
2224
+
2225
+ * Fix `find_in_batches` crashing when IDs are strings and start option is not specified.
2226
+
2227
+ *Alexis Bernard*
2228
+
2229
+ * `AR::Base#attributes_before_type_cast` now returns unserialized values for serialized attributes.
2230
+
2231
+ *Nikita Afanasenko*
2232
+
2233
+ * Use query cache/uncache when using `DATABASE_URL`.
2234
+ Fixes #6951.
2235
+
2236
+ *kennyj*
2237
+
2238
+ * Fix bug where `update_columns` and `update_column` would not let you update the primary key column.
2239
+
2240
+ *Henrik Nyh*
2241
+
2242
+ * The `create_table` method raises an `ArgumentError` when the primary key column is redefined.
2243
+ Fixes #6378.
2244
+
2245
+ *Yves Senn*
2246
+
2247
+ * `ActiveRecord::AttributeMethods#[]` raises `ActiveModel::MissingAttributeError`
2248
+ error if the given attribute is missing. Fixes #5433.
2249
+
2250
+ class Person < ActiveRecord::Base
2251
+ belongs_to :company
2252
+ end
2253
+
2254
+ # Before:
2255
+ person = Person.select('id').first
2256
+ person[:name] # => nil
2257
+ person.name # => ActiveModel::MissingAttributeError: missing_attribute: name
2258
+ person[:company_id] # => nil
2259
+ person.company # => nil
2260
+
2261
+ # After:
2262
+ person = Person.select('id').first
2263
+ person[:name] # => ActiveModel::MissingAttributeError: missing_attribute: name
2264
+ person.name # => ActiveModel::MissingAttributeError: missing_attribute: name
2265
+ person[:company_id] # => ActiveModel::MissingAttributeError: missing_attribute: company_id
2266
+ person.company # => ActiveModel::MissingAttributeError: missing_attribute: company_id
2267
+
2268
+ *Francesco Rodriguez*
2269
+
2270
+ * Small binary fields use the `VARBINARY` MySQL type, instead of `TINYBLOB`.
2271
+
2272
+ *Victor Costan*
2273
+
2274
+ * Decode URI encoded attributes on database connection URLs.
2275
+
2276
+ *Shawn Veader*
2277
+
2278
+ * Add `find_or_create_by`, `find_or_create_by!` and
2279
+ `find_or_initialize_by` methods to `Relation`.
2280
+
2281
+ These are similar to the `first_or_create` family of methods, but
2282
+ the behaviour when a record is created is slightly different:
2283
+
2284
+ User.where(first_name: 'Penélope').first_or_create
2285
+
2286
+ will execute:
2287
+
2288
+ User.where(first_name: 'Penélope').create
2289
+
2290
+ Causing all the `create` callbacks to execute within the context of
2291
+ the scope. This could affect queries that occur within callbacks.
2292
+
2293
+ User.find_or_create_by(first_name: 'Penélope')
2294
+
2295
+ will execute:
2296
+
2297
+ User.create(first_name: 'Penélope')
2298
+
2299
+ Which obviously does not affect the scoping of queries within
2300
+ callbacks.
2301
+
2302
+ The `find_or_create_by` version also reads better, frankly.
2303
+
2304
+ If you need to add extra attributes during create, you can do one of:
2305
+
2306
+ User.create_with(active: true).find_or_create_by(first_name: 'Jon')
2307
+ User.find_or_create_by(first_name: 'Jon') { |u| u.active = true }
2308
+
2309
+ The `first_or_create` family of methods have been nodoc'ed in favour
2310
+ of this API. They may be deprecated in the future but their
2311
+ implementation is very small and it's probably not worth putting users
2312
+ through lots of annoying deprecation warnings.
2313
+
2314
+ *Jon Leighton*
2315
+
2316
+ * Fix bug with presence validation of associations. Would incorrectly add duplicated errors
2317
+ when the association was blank. Bug introduced in 1fab518c6a75dac5773654646eb724a59741bc13.
2318
+
2319
+ *Scott Willson*
2320
+
2321
+ * Fix bug where sum(expression) returns string '0' for no matching records.
2322
+ Fixes #7439
2323
+
2324
+ *Tim Macfarlane*
2325
+
2326
+ * PostgreSQL adapter correctly fetches default values when using multiple schemas and domains in a db. Fixes #7914
2327
+
2328
+ *Arturo Pie*
2329
+
2330
+ * Learn ActiveRecord::QueryMethods#order work with hash arguments
2331
+
2332
+ When symbol or hash passed we convert it to Arel::Nodes::Ordering.
2333
+ If we pass invalid direction(like name: :DeSc) ActiveRecord::QueryMethods#order will raise an exception
2334
+
2335
+ User.order(:name, email: :desc)
2336
+ # SELECT "users".* FROM "users" ORDER BY "users"."name" ASC, "users"."email" DESC
2337
+
2338
+ *Tima Maslyuchenko*
2339
+
2340
+ * Rename `ActiveRecord::Fixtures` class to `ActiveRecord::FixtureSet`.
2341
+ Instances of this class normally hold a collection of fixtures (records)
2342
+ loaded either from a single YAML file, or from a file and a folder
2343
+ with the same name. This change make the class name singular and makes
2344
+ the class easier to distinguish from the modules like
2345
+ `ActiveRecord::TestFixtures`, which operates on multiple fixture sets,
2346
+ or `DelegatingFixtures`, `::Fixtures`, etc.,
2347
+ and from the class `ActiveRecord::Fixture`, which corresponds to a single
2348
+ fixture.
2349
+
2350
+ *Alexey Muranov*
2351
+
2352
+ * The postgres adapter now supports tables with capital letters.
2353
+ Fixes #5920.
2354
+
2355
+ *Yves Senn*
2356
+
2357
+ * `CollectionAssociation#count` returns `0` without querying if the
2358
+ parent record is not persisted.
2359
+
2360
+ Before:
2361
+
2362
+ person.pets.count
2363
+ # SELECT COUNT(*) FROM "pets" WHERE "pets"."person_id" IS NULL
2364
+ # => 0
2365
+
2366
+ After:
2367
+
2368
+ person.pets.count
2369
+ # fires without sql query
2370
+ # => 0
2371
+
2372
+ *Francesco Rodriguez*
2373
+
2374
+ * Fix `reset_counters` crashing on `has_many :through` associations.
2375
+ Fixes #7822.
2376
+
2377
+ *lulalala*
2378
+
2379
+ * Support for partial inserts.
2380
+
2381
+ When inserting new records, only the fields which have been changed
2382
+ from the defaults will actually be included in the INSERT statement.
2383
+ The other fields will be populated by the database.
2384
+
2385
+ This is more efficient, and also means that it will be safe to
2386
+ remove database columns without getting subsequent errors in running
2387
+ app processes (so long as the code in those processes doesn't
2388
+ contain any references to the removed column).
2389
+
2390
+ The `partial_updates` configuration option is now renamed to
2391
+ `partial_writes` to reflect the fact that it now impacts both inserts
2392
+ and updates.
2393
+
2394
+ *Jon Leighton*
2395
+
2396
+ * Allow before and after validations to take an array of lifecycle events
2397
+
2398
+ *John Foley*
2399
+
2400
+ * Support for specifying transaction isolation level
2401
+
2402
+ If your database supports setting the isolation level for a transaction, you can set
2403
+ it like so:
2404
+
2405
+ Post.transaction(isolation: :serializable) do
2406
+ # ...
2407
+ end
2408
+
2409
+ Valid isolation levels are:
2410
+
2411
+ * `:read_uncommitted`
2412
+ * `:read_committed`
2413
+ * `:repeatable_read`
2414
+ * `:serializable`
2415
+
2416
+ You should consult the documentation for your database to understand the
2417
+ semantics of these different levels:
2418
+
2419
+ * http://www.postgresql.org/docs/9.1/static/transaction-iso.html
2420
+ * https://dev.mysql.com/doc/refman/5.0/en/set-transaction.html
2421
+
2422
+ An `ActiveRecord::TransactionIsolationError` will be raised if:
2423
+
2424
+ * The adapter does not support setting the isolation level
2425
+ * You are joining an existing open transaction
2426
+ * You are creating a nested (savepoint) transaction
2427
+
2428
+ The mysql, mysql2 and postgresql adapters support setting the transaction
2429
+ isolation level. However, support is disabled for mysql versions below 5,
2430
+ because they are affected by a bug (http://bugs.mysql.com/bug.php?id=39170)
2431
+ which means the isolation level gets persisted outside the transaction.
2432
+
2433
+ *Jon Leighton*
2434
+
2435
+ * `ActiveModel::ForbiddenAttributesProtection` is included by default
2436
+ in Active Record models. Check the docs of `ActiveModel::ForbiddenAttributesProtection`
2437
+ for more details.
2438
+
2439
+ *Guillermo Iguaran*
2440
+
2441
+ * Remove integration between Active Record and
2442
+ `ActiveModel::MassAssignmentSecurity`, `protected_attributes` gem
2443
+ should be added to use `attr_accessible`/`attr_protected`. Mass
2444
+ assignment options has been removed from all the AR methods that
2445
+ used it (ex. `AR::Base.new`, `AR::Base.create`, `AR::Base#update_attributes`, etc).
2446
+
2447
+ *Guillermo Iguaran*
2448
+
2449
+ * Fix the return of querying with an empty hash.
2450
+ Fixes #6971.
2451
+
2452
+ User.where(token: {})
2453
+
2454
+ Before:
2455
+
2456
+ #=> SELECT * FROM users;
2457
+
2458
+ After:
2459
+
2460
+ #=> SELECT * FROM users WHERE 1=0;
2461
+
2462
+ *Damien Mathieu*
2463
+
2464
+ * Fix creation of through association models when using `collection=[]`
2465
+ on a `has_many :through` association from an unsaved model.
2466
+ Fixes #7661.
2467
+
2468
+ *Ernie Miller*
2469
+
2470
+ * Explain only normal CRUD sql (select / update / insert / delete).
2471
+ Fix problem that explains unexplainable sql.
2472
+ Fixes #7544 #6458.
2473
+
2474
+ *kennyj*
2475
+
2476
+ * You can now override the generated accessor methods for stored attributes
2477
+ and reuse the original behavior with `read_store_attribute` and `write_store_attribute`,
2478
+ which are counterparts to `read_attribute` and `write_attribute`.
2479
+
2480
+ *Matt Jones*
2481
+
2482
+ * Accept `belongs_to` (including polymorphic) association keys in queries.
2483
+
2484
+ The following queries are now equivalent:
2485
+
2486
+ Post.where(author: author)
2487
+ Post.where(author_id: author)
2488
+
2489
+ PriceEstimate.where(estimate_of: treasure)
2490
+ PriceEstimate.where(estimate_of_type: 'Treasure', estimate_of_id: treasure)
2491
+
2492
+ *Peter Brown*
2493
+
2494
+ * Use native `mysqldump` command instead of `structure_dump` method
2495
+ when dumping the database structure to a sql file. Fixes #5547.
2496
+
2497
+ *kennyj*
874
2498
 
875
- * Implements `AR::Base.silence_auto_explain`. This method allows the user to
876
- selectively disable automatic EXPLAINs within a block. *fxn*
2499
+ * PostgreSQL inet and cidr types are converted to `IPAddr` objects.
877
2500
 
878
- * Implements automatic EXPLAIN logging for slow queries.
2501
+ *Dan McClain*
879
2502
 
880
- A new configuration parameter `config.active_record.auto_explain_threshold_in_seconds`
881
- determines what's to be considered a slow query. Setting that to `nil` disables
882
- this feature. Defaults are 0.5 in development mode, and `nil` in test and production
883
- modes.
2503
+ * PostgreSQL array type support. Any datatype can be used to create an
2504
+ array column, with full migration and schema dumper support.
884
2505
 
885
- As of this writing there's support for SQLite, MySQL (mysql2 adapter), and
886
- PostgreSQL.
2506
+ To declare an array column, use the following syntax:
887
2507
 
888
- *fxn*
2508
+ create_table :table_with_arrays do |t|
2509
+ t.integer :int_array, array: true
2510
+ # integer[]
2511
+ t.integer :int_array, array: true, length: 2
2512
+ # smallint[]
2513
+ t.string :string_array, array: true, length: 30
2514
+ # char varying(30)[]
2515
+ end
889
2516
 
890
- * Implemented ActiveRecord::Relation#pluck method
2517
+ This respects any other migration detail (limits, defaults, etc).
2518
+ Active Record will serialize and deserialize the array columns on
2519
+ their way to and from the database.
891
2520
 
892
- Method returns Array of column value from table under ActiveRecord model
2521
+ One thing to note: PostgreSQL does not enforce any limits on the
2522
+ number of elements, and any array can be multi-dimensional. Any
2523
+ array that is multi-dimensional must be rectangular (each sub array
2524
+ must have the same number of elements as its siblings).
893
2525
 
894
- Client.pluck(:id)
2526
+ If the `pg_array_parser` gem is available, it will be used when
2527
+ parsing PostgreSQL's array representation.
895
2528
 
896
- *Bogdan Gusiev*
2529
+ *Dan McClain*
2530
+
2531
+ * Attribute predicate methods, such as `article.title?`, will now raise
2532
+ `ActiveModel::MissingAttributeError` if the attribute being queried for
2533
+ truthiness was not read from the database, instead of just returning `false`.
2534
+
2535
+ *Ernie Miller*
2536
+
2537
+ * `ActiveRecord::SchemaDumper` uses Ruby 1.9 style hash, which means that the
2538
+ schema.rb file will be generated using this new syntax from now on.
2539
+
2540
+ *Konstantin Shabanov*
2541
+
2542
+ * Map interval with precision to string datatype in PostgreSQL. Fixes #7518.
2543
+
2544
+ *Yves Senn*
2545
+
2546
+ * Fix eagerly loading associations without primary keys. Fixes #4976.
2547
+
2548
+ *Kelley Reynolds*
2549
+
2550
+ * Rails now raise an exception when you're trying to run a migration that has an invalid
2551
+ file name. Only lower case letters, numbers, and '_' are allowed in migration's file name.
2552
+ Please see #7419 for more details.
2553
+
2554
+ *Jan Bernacki*
2555
+
2556
+ * Fix bug when calling `store_accessor` multiple times.
2557
+ Fixes #7532.
2558
+
2559
+ *Matt Jones*
2560
+
2561
+ * Fix store attributes that show the changes incorrectly.
2562
+ Fixes #7532.
2563
+
2564
+ *Matt Jones*
2565
+
2566
+ * Fix `ActiveRecord::Relation#pluck` when columns or tables are reserved words.
2567
+
2568
+ *Ian Lesperance*
2569
+
2570
+ * Allow JSON columns to be created in PostgreSQL and properly encoded/decoded.
2571
+ to/from database.
2572
+
2573
+ *Dickson S. Guedes*
2574
+
2575
+ * Fix time column type casting for invalid time string values to correctly return `nil`.
2576
+
2577
+ *Adam Meehan*
2578
+
2579
+ * Allow to pass Symbol or Proc into `:limit` option of #accepts_nested_attributes_for.
2580
+
2581
+ *Mikhail Dieterle*
2582
+
2583
+ * ActiveRecord::SessionStore has been extracted from Active Record as `activerecord-session_store`
2584
+ gem. Please read the `README.md` file on the gem for the usage.
2585
+
2586
+ *Prem Sichanugrist*
2587
+
2588
+ * Fix `reset_counters` when there are multiple `belongs_to` association with the
2589
+ same foreign key and one of them have a counter cache.
2590
+ Fixes #5200.
2591
+
2592
+ *Dave Desrochers*
2593
+
2594
+ * `serialized_attributes` and `_attr_readonly` become class method only. Instance reader methods are deprecated.
2595
+
2596
+ *kennyj*
2597
+
2598
+ * Round usec when comparing timestamp attributes in the dirty tracking.
2599
+ Fixes #6975.
2600
+
2601
+ *kennyj*
2602
+
2603
+ * Use inversed parent for first and last child of `has_many` association.
2604
+
2605
+ *Ravil Bayramgalin*
2606
+
2607
+ * Fix `Column.microseconds` and `Column.fast_string_to_time` to avoid converting
2608
+ timestamp seconds to a float, since it occasionally results in inaccuracies
2609
+ with microsecond-precision times. Fixes #7352.
2610
+
2611
+ *Ari Pollak*
2612
+
2613
+ * Fix AR#dup to nullify the validation errors in the dup'ed object. Previously the original
2614
+ and the dup'ed object shared the same errors.
2615
+
2616
+ *Christian Seiler*
2617
+
2618
+ * Raise `ArgumentError` if list of attributes to change is empty in `update_all`.
2619
+
2620
+ *Roman Shatsov*
2621
+
2622
+ * Fix AR#create to return an unsaved record when AR::RecordInvalid is
2623
+ raised. Fixes #3217.
2624
+
2625
+ *Dave Yeu*
2626
+
2627
+ * Fixed table name prefix that is generated in engines for namespaced models.
2628
+
2629
+ *Wojciech Wnętrzak*
2630
+
2631
+ * Make sure `:environment` task is executed before `db:schema:load` or `db:structure:load`.
2632
+ Fixes #4772.
897
2633
 
898
- * Automatic closure of connections in threads is deprecated. For example
899
- the following code is deprecated:
2634
+ *Seamus Abshere*
2635
+
2636
+ * Allow Relation#merge to take a proc.
900
2637
 
901
- Thread.new { Post.find(1) }.join
2638
+ This was requested by DHH to allow creating of one's own custom
2639
+ association macros.
902
2640
 
903
- It should be changed to close the database connection at the end of
904
- the thread:
2641
+ For example:
905
2642
 
906
- Thread.new {
907
- Post.find(1)
908
- Post.connection.close
909
- }.join
2643
+ module Commentable
2644
+ def has_many_comments(extra)
2645
+ has_many :comments, -> { where(:foo).merge(extra) }
2646
+ end
2647
+ end
910
2648
 
911
- Only people who spawn threads in their application code need to worry
912
- about this change.
2649
+ class Post < ActiveRecord::Base
2650
+ extend Commentable
2651
+ has_many_comments -> { where(:bar) }
2652
+ end
913
2653
 
914
- * Deprecated:
2654
+ *Jon Leighton*
915
2655
 
916
- * `set_table_name`
917
- * `set_inheritance_column`
918
- * `set_sequence_name`
919
- * `set_primary_key`
920
- * `set_locking_column`
2656
+ * Add CollectionProxy#scope.
921
2657
 
922
- Use an assignment method instead. For example, instead of `set_table_name`, use `self.table_name=`:
2658
+ This can be used to get a Relation from an association.
923
2659
 
924
- class Project < ActiveRecord::Base
925
- self.table_name = "project"
926
- end
2660
+ Previously we had a #scoped method, but we're deprecating that for
2661
+ AR::Base, so it doesn't make sense to have it here.
927
2662
 
928
- Or define your own `self.table_name` method:
2663
+ This was requested by DHH, to facilitate code like this:
929
2664
 
930
- class Post < ActiveRecord::Base
931
- def self.table_name
932
- "special_" + super
933
- end
934
- end
935
- Post.table_name # => "special_posts"
2665
+ Project.scope.order('created_at DESC').page(current_page).tagged_with(@tag).limit(5).scoping do
2666
+ @topics = @project.topics.scope
2667
+ @todolists = @project.todolists.scope
2668
+ @attachments = @project.attachments.scope
2669
+ @documents = @project.documents.scope
2670
+ end
936
2671
 
937
2672
  *Jon Leighton*
938
2673
 
939
- * Generated association methods are created within a separate module to allow overriding and
940
- composition using `super`. For a class named `MyModel`, the module is named
941
- `MyModel::GeneratedFeatureMethods`. It is included into the model class immediately after
942
- the `generated_attributes_methods` module defined in ActiveModel, so association methods
943
- override attribute methods of the same name. *Josh Susser*
2674
+ * Add `Relation#load`.
944
2675
 
945
- * Implemented ActiveRecord::Relation#explain. *fxn*
2676
+ This method explicitly loads the records and then returns `self`.
946
2677
 
947
- * Add ActiveRecord::Relation#uniq for generating unique queries.
2678
+ Rather than deciding between "do I want an array or a relation?",
2679
+ most people are actually asking themselves "do I want to eager load
2680
+ or lazy load?" Therefore, this method provides a way to explicitly
2681
+ eager-load without having to switch from a `Relation` to an array.
948
2682
 
949
- Before:
2683
+ Example:
950
2684
 
951
- Client.select('DISTINCT name')
2685
+ @posts = Post.where(published: true).load
952
2686
 
953
- After:
2687
+ *Jon Leighton*
2688
+
2689
+ * `Relation#order`: make new order prepend old one.
2690
+
2691
+ User.order("name asc").order("created_at desc")
2692
+ # SELECT * FROM users ORDER BY created_at desc, name asc
2693
+
2694
+ This also affects order defined in `default_scope` or any kind of associations.
2695
+
2696
+ *Bogdan Gusiev*
954
2697
 
955
- Client.select(:name).uniq
2698
+ * `Model.all` now returns an `ActiveRecord::Relation`, rather than an
2699
+ array of records. Use `Relation#to_a` if you really want an array.
956
2700
 
957
- This also allows you to revert the unqueness in a relation:
2701
+ In some specific cases, this may cause breakage when upgrading.
2702
+ However in most cases the `ActiveRecord::Relation` will just act as a
2703
+ lazy-loaded array and there will be no problems.
958
2704
 
959
- Client.select(:name).uniq.uniq(false)
2705
+ Note that calling `Model.all` with options (e.g.
2706
+ `Model.all(conditions: '...')` was already deprecated, but it will
2707
+ still return an array in order to make the transition easier.
2708
+
2709
+ `Model.scoped` is deprecated in favour of `Model.all`.
2710
+
2711
+ `Relation#all` still returns an array, but is deprecated (since it
2712
+ would serve no purpose if we made it return a `Relation`).
960
2713
 
961
2714
  *Jon Leighton*
962
2715
 
963
- * Support index sort order in sqlite, mysql and postgres adapters. *Vlad Jebelev*
2716
+ * `:finder_sql` and `:counter_sql` options on collection associations
2717
+ are deprecated. Please transition to using scopes.
964
2718
 
965
- * Allow the :class_name option for associations to take a symbol (:Client) in addition to
966
- a string ('Client').
2719
+ *Jon Leighton*
967
2720
 
968
- This is to avoid confusing newbies, and to be consistent with the fact that other options
969
- like :foreign_key already allow a symbol or a string.
2721
+ * `:insert_sql` and `:delete_sql` options on `has_and_belongs_to_many`
2722
+ associations are deprecated. Please transition to using `has_many
2723
+ :through`.
970
2724
 
971
2725
  *Jon Leighton*
972
2726
 
973
- * In development mode the db:drop task also drops the test database. For symmetry with
974
- the db:create task. *Dmitriy Kiriyenko*
2727
+ * Added `#update_columns` method which updates the attributes from
2728
+ the passed-in hash without calling save, hence skipping validations and
2729
+ callbacks. `ActiveRecordError` will be raised when called on new objects
2730
+ or when at least one of the attributes is marked as read only.
975
2731
 
976
- * Added ActiveRecord::Base.store for declaring simple single-column key/value stores *DHH*
2732
+ post.attributes # => {"id"=>2, "title"=>"My title", "body"=>"My content", "author"=>"Peter"}
2733
+ post.update_columns(title: 'New title', author: 'Sebastian') # => true
2734
+ post.attributes # => {"id"=>2, "title"=>"New title", "body"=>"My content", "author"=>"Sebastian"}
977
2735
 
978
- class User < ActiveRecord::Base
979
- store :settings, accessors: [ :color, :homepage ]
2736
+ *Sebastian Martinez + Rafael Mendonça França*
2737
+
2738
+ * The migration generator now creates a join table with (commented) indexes every time
2739
+ the migration name contains the word `join_table`:
2740
+
2741
+ rails g migration create_join_table_for_artists_and_musics artist_id:index music_id
2742
+
2743
+ *Aleksey Magusev*
2744
+
2745
+ * Add `add_reference` and `remove_reference` schema statements. Aliases, `add_belongs_to`
2746
+ and `remove_belongs_to` are acceptable. References are reversible.
2747
+
2748
+ Examples:
2749
+
2750
+ # Create a user_id column
2751
+ add_reference(:products, :user)
2752
+ # Create a supplier_id, supplier_type columns and appropriate index
2753
+ add_reference(:products, :supplier, polymorphic: true, index: true)
2754
+ # Remove polymorphic reference
2755
+ remove_reference(:products, :supplier, polymorphic: true)
2756
+
2757
+ *Aleksey Magusev*
2758
+
2759
+ * Add `:default` and `:null` options to `column_exists?`.
2760
+
2761
+ column_exists?(:testings, :taggable_id, :integer, null: false)
2762
+ column_exists?(:testings, :taggable_type, :string, default: 'Photo')
2763
+
2764
+ *Aleksey Magusev*
2765
+
2766
+ * `ActiveRecord::Relation#inspect` now makes it clear that you are
2767
+ dealing with a `Relation` object rather than an array:.
2768
+
2769
+ User.where(age: 30).inspect
2770
+ # => <ActiveRecord::Relation [#<User ...>, #<User ...>, ...]>
2771
+
2772
+ User.where(age: 30).to_a.inspect
2773
+ # => [#<User ...>, #<User ...>]
2774
+
2775
+ The number of records displayed will be limited to 10.
2776
+
2777
+ *Brian Cardarella, Jon Leighton & Damien Mathieu*
2778
+
2779
+ * Add `collation` and `ctype` support to PostgreSQL. These are available for PostgreSQL 8.4 or later.
2780
+ Example:
2781
+
2782
+ development:
2783
+ adapter: postgresql
2784
+ host: localhost
2785
+ database: rails_development
2786
+ username: foo
2787
+ password: bar
2788
+ encoding: UTF8
2789
+ collation: ja_JP.UTF8
2790
+ ctype: ja_JP.UTF8
2791
+
2792
+ *kennyj*
2793
+
2794
+ * Changed `validates_presence_of` on an association so that children objects
2795
+ do not validate as being present if they are marked for destruction. This
2796
+ prevents you from saving the parent successfully and thus putting the parent
2797
+ in an invalid state.
2798
+
2799
+ *Nick Monje & Brent Wheeldon*
2800
+
2801
+ * `FinderMethods#exists?` now returns `false` with the `false` argument.
2802
+
2803
+ *Egor Lynko*
2804
+
2805
+ * Added support for specifying the precision of a timestamp in the PostgreSQL
2806
+ adapter. So, instead of having to incorrectly specify the precision using the
2807
+ `:limit` option, you may use `:precision`, as intended. For example, in a migration:
2808
+
2809
+ def change
2810
+ create_table :foobars do |t|
2811
+ t.timestamps precision: 0
2812
+ end
2813
+ end
2814
+
2815
+ *Tony Schneider*
2816
+
2817
+ * Allow `ActiveRecord::Relation#pluck` to accept multiple columns. Returns an
2818
+ array of arrays containing the typecasted values:
2819
+
2820
+ Person.pluck(:id, :name)
2821
+ # SELECT people.id, people.name FROM people
2822
+ # [[1, 'David'], [2, 'Jeremy'], [3, 'Jose']]
2823
+
2824
+ *Jeroen van Ingen & Carlos Antonio da Silva*
2825
+
2826
+ * Improve the derivation of HABTM join table name to take account of nesting.
2827
+ It now takes the table names of the two models, sorts them lexically and
2828
+ then joins them, stripping any common prefix from the second table name.
2829
+
2830
+ Some examples:
2831
+
2832
+ Top level models (Category <=> Product)
2833
+ Old: categories_products
2834
+ New: categories_products
2835
+
2836
+ Top level models with a global table_name_prefix (Category <=> Product)
2837
+ Old: site_categories_products
2838
+ New: site_categories_products
2839
+
2840
+ Nested models in a module without a table_name_prefix method (Admin::Category <=> Admin::Product)
2841
+ Old: categories_products
2842
+ New: categories_products
2843
+
2844
+ Nested models in a module with a table_name_prefix method (Admin::Category <=> Admin::Product)
2845
+ Old: categories_products
2846
+ New: admin_categories_products
2847
+
2848
+ Nested models in a parent model (Catalog::Category <=> Catalog::Product)
2849
+ Old: categories_products
2850
+ New: catalog_categories_products
2851
+
2852
+ Nested models in different parent models (Catalog::Category <=> Content::Page)
2853
+ Old: categories_pages
2854
+ New: catalog_categories_content_pages
2855
+
2856
+ *Andrew White*
2857
+
2858
+ * Move HABTM validity checks to `ActiveRecord::Reflection`. One side effect of
2859
+ this is to move when the exceptions are raised from the point of declaration
2860
+ to when the association is built. This is consistent with other association
2861
+ validity checks.
2862
+
2863
+ *Andrew White*
2864
+
2865
+ * Added `stored_attributes` hash which contains the attributes stored using
2866
+ `ActiveRecord::Store`. This allows you to retrieve the list of attributes
2867
+ you've defined.
2868
+
2869
+ class User < ActiveRecord::Base
2870
+ store :settings, accessors: [:color, :homepage]
2871
+ end
2872
+
2873
+ User.stored_attributes[:settings] # [:color, :homepage]
2874
+
2875
+ *Joost Baaij & Carlos Antonio da Silva*
2876
+
2877
+ * PostgreSQL default log level is now 'warning', to bypass the noisy notice
2878
+ messages. You can change the log level using the `min_messages` option
2879
+ available in your config/database.yml.
2880
+
2881
+ *kennyj*
2882
+
2883
+ * Add uuid datatype support to PostgreSQL adapter.
2884
+
2885
+ *Konstantin Shabanov*
2886
+
2887
+ * Added `ActiveRecord::Migration.check_pending!` that raises an error if
2888
+ migrations are pending.
2889
+
2890
+ *Richard Schneeman*
2891
+
2892
+ * Added `#destroy!` which acts like `#destroy` but will raise an
2893
+ `ActiveRecord::RecordNotDestroyed` exception instead of returning `false`.
2894
+
2895
+ *Marc-André Lafortune*
2896
+
2897
+ * Added support to `CollectionAssociation#delete` for passing `fixnum`
2898
+ or `string` values as record ids. This finds the records responding
2899
+ to the `id` and executes delete on them.
2900
+
2901
+ class Person < ActiveRecord::Base
2902
+ has_many :pets
980
2903
  end
981
2904
 
982
- u = User.new(color: 'black', homepage: '37signals.com')
983
- u.color # Accessor stored attribute
984
- u.settings[:country] = 'Denmark' # Any attribute, even if not specified with an accessor
2905
+ person.pets.delete("1") # => [#<Pet id: 1>]
2906
+ person.pets.delete(2, 3) # => [#<Pet id: 2>, #<Pet id: 3>]
2907
+
2908
+ *Francesco Rodriguez*
2909
+
2910
+ * Deprecated most of the 'dynamic finder' methods. All dynamic methods
2911
+ except for `find_by_...` and `find_by_...!` are deprecated. Here's
2912
+ how you can rewrite the code:
2913
+
2914
+ * `find_all_by_...` can be rewritten using `where(...)`
2915
+ * `find_last_by_...` can be rewritten using `where(...).last`
2916
+ * `scoped_by_...` can be rewritten using `where(...)`
2917
+ * `find_or_initialize_by_...` can be rewritten using
2918
+ `where(...).first_or_initialize`
2919
+ * `find_or_create_by_...` can be rewritten using
2920
+ `find_or_create_by(...)` or where(...).first_or_create`
2921
+ * `find_or_create_by_...!` can be rewritten using
2922
+ `find_or_create_by!(...) or `where(...).first_or_create!`
2923
+
2924
+ The implementation of the deprecated dynamic finders has been moved
2925
+ to the `activerecord-deprecated_finders` gem. See below for details.
2926
+
2927
+ *Jon Leighton*
2928
+
2929
+ * Deprecated the old-style hash based finder API. This means that
2930
+ methods which previously accepted "finder options" no longer do. For
2931
+ example this:
2932
+
2933
+ Post.find(:all, conditions: { comments_count: 10 }, limit: 5)
2934
+
2935
+ Should be rewritten in the new style which has existed since Rails 3:
2936
+
2937
+ Post.where(comments_count: 10).limit(5)
2938
+
2939
+ Note that as an interim step, it is possible to rewrite the above as:
2940
+
2941
+ Post.all.merge(where: { comments_count: 10 }, limit: 5)
2942
+
2943
+ This could save you a lot of work if there is a lot of old-style
2944
+ finder usage in your application.
2945
+
2946
+ `Relation#merge` now accepts a hash of
2947
+ options, but they must be identical to the names of the equivalent
2948
+ finder method. These are mostly identical to the old-style finder
2949
+ option names, except in the following cases:
2950
+
2951
+ * `:conditions` becomes `:where`.
2952
+ * `:include` becomes `:includes`.
2953
+
2954
+ The code to implement the deprecated features has been moved out to the
2955
+ `activerecord-deprecated_finders` gem. This gem is a dependency of Active
2956
+ Record in Rails 4.0, so the interface works out of the box. It will no
2957
+ longer be a dependency from Rails 4.1 (you'll need to add it to the
2958
+ `Gemfile` in 4.1), and will be maintained until Rails 5.0.
2959
+
2960
+ *Jon Leighton*
2961
+
2962
+ * It's not possible anymore to destroy a model marked as read only.
2963
+
2964
+ *Johannes Barre*
2965
+
2966
+ * Added ability to ActiveRecord::Relation#from to accept other ActiveRecord::Relation objects.
2967
+
2968
+ Record.from(subquery)
2969
+ Record.from(subquery, :a)
2970
+
2971
+ *Radoslav Stankov*
2972
+
2973
+ * Added custom coders support for ActiveRecord::Store. Now you can set
2974
+ your custom coder like this:
2975
+
2976
+ store :settings, accessors: [ :color, :homepage ], coder: JSON
2977
+
2978
+ *Andrey Voronkov*
2979
+
2980
+ * `mysql` and `mysql2` connections will set `SQL_MODE=STRICT_ALL_TABLES` by
2981
+ default to avoid silent data loss. This can be disabled by specifying
2982
+ `strict: false` in your `database.yml`.
2983
+
2984
+ *Michael Pearson*
2985
+
2986
+ * Added default order to `first` to assure consistent results among
2987
+ different database engines. Introduced `take` as a replacement to
2988
+ the old behavior of `first`.
2989
+
2990
+ *Marcelo Silveira*
2991
+
2992
+ * Added an `:index` option to automatically create indexes for references
2993
+ and belongs_to statements in migrations.
2994
+
2995
+ The `references` and `belongs_to` methods now support an `index`
2996
+ option that receives either a boolean value or an options hash
2997
+ that is identical to options available to the add_index method:
2998
+
2999
+ create_table :messages do |t|
3000
+ t.references :person, index: true
3001
+ end
3002
+
3003
+ Is the same as:
3004
+
3005
+ create_table :messages do |t|
3006
+ t.references :person
3007
+ end
3008
+ add_index :messages, :person_id
985
3009
 
3010
+ Generators have also been updated to use the new syntax.
986
3011
 
987
- * MySQL: case-insensitive uniqueness validation avoids calling LOWER when
988
- the column already uses a case-insensitive collation. Fixes #561.
3012
+ *Joshua Wood*
989
3013
 
990
- *Joseph Palermo*
3014
+ * Added `#find_by` and `#find_by!` to mirror the functionality
3015
+ provided by dynamic finders in a way that allows dynamic input more
3016
+ easily:
991
3017
 
992
- * Transactional fixtures enlist all active database connections. You can test
993
- models on different connections without disabling transactional fixtures.
3018
+ Post.find_by name: 'Spartacus', rating: 4
3019
+ Post.find_by "published_at < ?", 2.weeks.ago
3020
+ Post.find_by! name: 'Spartacus'
3021
+
3022
+ *Jon Leighton*
3023
+
3024
+ * Added ActiveRecord::Base#slice to return a hash of the given methods with
3025
+ their names as keys and returned values as values.
3026
+
3027
+ *Guillermo Iguaran*
3028
+
3029
+ * Deprecate eager-evaluated scopes.
3030
+
3031
+ Don't use this:
3032
+
3033
+ scope :red, where(color: 'red')
3034
+ default_scope where(color: 'red')
3035
+
3036
+ Use this:
3037
+
3038
+ scope :red, -> { where(color: 'red') }
3039
+ default_scope { where(color: 'red') }
3040
+
3041
+ The former has numerous issues. It is a common newbie gotcha to do
3042
+ the following:
3043
+
3044
+ scope :recent, where(published_at: Time.now - 2.weeks)
3045
+
3046
+ Or a more subtle variant:
3047
+
3048
+ scope :recent, -> { where(published_at: Time.now - 2.weeks) }
3049
+ scope :recent_red, recent.where(color: 'red')
3050
+
3051
+ Eager scopes are also very complex to implement within Active
3052
+ Record, and there are still bugs. For example, the following does
3053
+ not do what you expect:
3054
+
3055
+ scope :remove_conditions, except(:where)
3056
+ where(...).remove_conditions # => still has conditions
3057
+
3058
+ *Jon Leighton*
3059
+
3060
+ * Remove IdentityMap
3061
+
3062
+ IdentityMap has never graduated to be an "enabled-by-default" feature, due
3063
+ to some inconsistencies with associations, as described in this commit:
3064
+
3065
+ https://github.com/rails/rails/commit/302c912bf6bcd0fa200d964ec2dc4a44abe328a6
3066
+
3067
+ Hence the removal from the codebase, until such issues are fixed.
3068
+
3069
+ *Carlos Antonio da Silva*
3070
+
3071
+ * Added the schema cache dump feature.
3072
+
3073
+ `Schema cache dump` feature was implemented. This feature can dump/load internal state of `SchemaCache` instance
3074
+ because we want to boot rails more quickly when we have many models.
3075
+
3076
+ Usage notes:
3077
+
3078
+ 1) execute rake task.
3079
+ RAILS_ENV=production bundle exec rake db:schema:cache:dump
3080
+ => generate db/schema_cache.dump
3081
+
3082
+ 2) add config.active_record.use_schema_cache_dump = true in config/production.rb. BTW, true is default.
3083
+
3084
+ 3) boot rails.
3085
+ RAILS_ENV=production bundle exec rails server
3086
+ => use db/schema_cache.dump
3087
+
3088
+ 4) If you remove clear dumped cache, execute rake task.
3089
+ RAILS_ENV=production bundle exec rake db:schema:cache:clear
3090
+ => remove db/schema_cache.dump
3091
+
3092
+ *kennyj*
3093
+
3094
+ * Added support for partial indices to PostgreSQL adapter.
3095
+
3096
+ The `add_index` method now supports a `where` option that receives a
3097
+ string with the partial index criteria.
3098
+
3099
+ add_index(:accounts, :code, where: 'active')
3100
+
3101
+ generates
3102
+
3103
+ CREATE INDEX index_accounts_on_code ON accounts(code) WHERE active
3104
+
3105
+ *Marcelo Silveira*
3106
+
3107
+ * Implemented `ActiveRecord::Relation#none` method.
3108
+
3109
+ The `none` method returns a chainable relation with zero records
3110
+ (an instance of the NullRelation class).
3111
+
3112
+ Any subsequent condition chained to the returned relation will continue
3113
+ generating an empty relation and will not fire any query to the database.
3114
+
3115
+ *Juanjo Bazán*
3116
+
3117
+ * Added the `ActiveRecord::NullRelation` class implementing the null
3118
+ object pattern for the Relation class.
3119
+
3120
+ *Juanjo Bazán*
3121
+
3122
+ * Added new `dependent: :restrict_with_error` option. This will add
3123
+ an error to the model, rather than raising an exception.
3124
+
3125
+ The `:restrict` option is renamed to `:restrict_with_exception` to
3126
+ make this distinction explicit.
3127
+
3128
+ *Manoj Kumar & Jon Leighton*
3129
+
3130
+ * Added `create_join_table` migration helper to create HABTM join tables.
3131
+
3132
+ create_join_table :products, :categories
3133
+ # =>
3134
+ # create_table :categories_products, id: false do |td|
3135
+ # td.integer :product_id, null: false
3136
+ # td.integer :category_id, null: false
3137
+ # end
3138
+
3139
+ *Rafael Mendonça França*
3140
+
3141
+ * The primary key is always initialized in the @attributes hash to `nil` (unless
3142
+ another value has been specified).
3143
+
3144
+ *Aaron Patterson*
3145
+
3146
+ * In previous releases, the following would generate a single query with
3147
+ an `OUTER JOIN comments`, rather than two separate queries:
3148
+
3149
+ Post.includes(:comments)
3150
+ .where("comments.name = 'foo'")
3151
+
3152
+ This behaviour relies on matching SQL string, which is an inherently
3153
+ flawed idea unless we write an SQL parser, which we do not wish to
3154
+ do.
3155
+
3156
+ Therefore, it is now deprecated.
3157
+
3158
+ To avoid deprecation warnings and for future compatibility, you must
3159
+ explicitly state which tables you reference, when using SQL snippets:
3160
+
3161
+ Post.includes(:comments)
3162
+ .where("comments.name = 'foo'")
3163
+ .references(:comments)
3164
+
3165
+ Note that you do not need to explicitly specify references in the
3166
+ following cases, as they can be automatically inferred:
3167
+
3168
+ Post.includes(:comments).where(comments: { name: 'foo' })
3169
+ Post.includes(:comments).where('comments.name' => 'foo')
3170
+ Post.includes(:comments).order('comments.name')
3171
+
3172
+ You do not need to worry about this unless you are doing eager
3173
+ loading. Basically, don't worry unless you see a deprecation warning
3174
+ or (in future releases) an SQL error due to a missing JOIN.
3175
+
3176
+ *Jon Leighton*
994
3177
 
995
- *Jeremy Kemper*
3178
+ * Support for the `schema_info` table has been dropped. Please
3179
+ switch to `schema_migrations`.
996
3180
 
997
- * Add first_or_create, first_or_create!, first_or_initialize methods to Active Record. This is a
998
- better approach over the old find_or_create_by dynamic methods because it's clearer which
999
- arguments are used to find the record and which are used to create it:
3181
+ *Aaron Patterson*
1000
3182
 
1001
- User.where(:first_name => "Scarlett").first_or_create!(:last_name => "Johansson")
3183
+ * Connections *must* be closed at the end of a thread. If not, your
3184
+ connection pool can fill and an exception will be raised.
1002
3185
 
1003
- *Andrés Mejía*
3186
+ *Aaron Patterson*
1004
3187
 
1005
- * Fix nested attributes bug where _destroy parameter is taken into account
1006
- during :reject_if => :all_blank (fixes #2937)
3188
+ * PostgreSQL hstore records can be created.
1007
3189
 
1008
- *Aaron Christy*
3190
+ *Aaron Patterson*
1009
3191
 
1010
- * Add ActiveSupport::Cache::NullStore for use in development and testing.
3192
+ * PostgreSQL hstore types are automatically deserialized from the database.
1011
3193
 
1012
- *Brian Durand*
3194
+ *Aaron Patterson*
1013
3195
 
1014
- Please check [3-1-stable](https://github.com/rails/rails/blob/3-1-stable/activerecord/CHANGELOG.md) for previous changes.
3196
+ Please check [3-2-stable](https://github.com/rails/rails/blob/3-2-stable/activerecord/CHANGELOG.md) for previous changes.