activerecord 4.0.13 → 4.1.0.beta1

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 (135) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +745 -2700
  3. data/README.rdoc +2 -2
  4. data/examples/performance.rb +30 -18
  5. data/examples/simple.rb +4 -4
  6. data/lib/active_record.rb +2 -6
  7. data/lib/active_record/aggregations.rb +2 -1
  8. data/lib/active_record/association_relation.rb +0 -4
  9. data/lib/active_record/associations.rb +87 -43
  10. data/lib/active_record/associations/alias_tracker.rb +1 -3
  11. data/lib/active_record/associations/association.rb +8 -16
  12. data/lib/active_record/associations/association_scope.rb +5 -16
  13. data/lib/active_record/associations/belongs_to_association.rb +34 -25
  14. data/lib/active_record/associations/belongs_to_polymorphic_association.rb +1 -1
  15. data/lib/active_record/associations/builder/association.rb +78 -54
  16. data/lib/active_record/associations/builder/belongs_to.rb +91 -58
  17. data/lib/active_record/associations/builder/collection_association.rb +47 -45
  18. data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +107 -25
  19. data/lib/active_record/associations/builder/has_many.rb +2 -2
  20. data/lib/active_record/associations/builder/has_one.rb +5 -7
  21. data/lib/active_record/associations/builder/singular_association.rb +6 -7
  22. data/lib/active_record/associations/collection_association.rb +68 -105
  23. data/lib/active_record/associations/collection_proxy.rb +12 -15
  24. data/lib/active_record/associations/has_many_association.rb +11 -9
  25. data/lib/active_record/associations/has_many_through_association.rb +16 -12
  26. data/lib/active_record/associations/has_one_association.rb +1 -1
  27. data/lib/active_record/associations/join_dependency.rb +204 -165
  28. data/lib/active_record/associations/join_dependency/join_association.rb +43 -101
  29. data/lib/active_record/associations/join_dependency/join_base.rb +6 -8
  30. data/lib/active_record/associations/join_dependency/join_part.rb +18 -37
  31. data/lib/active_record/associations/join_helper.rb +2 -11
  32. data/lib/active_record/associations/preloader.rb +89 -34
  33. data/lib/active_record/associations/preloader/association.rb +43 -25
  34. data/lib/active_record/associations/preloader/collection_association.rb +2 -2
  35. data/lib/active_record/associations/preloader/has_many_through.rb +1 -1
  36. data/lib/active_record/associations/preloader/singular_association.rb +3 -3
  37. data/lib/active_record/associations/preloader/through_association.rb +58 -26
  38. data/lib/active_record/associations/singular_association.rb +6 -5
  39. data/lib/active_record/associations/through_association.rb +2 -2
  40. data/lib/active_record/attribute_assignment.rb +5 -2
  41. data/lib/active_record/attribute_methods.rb +45 -40
  42. data/lib/active_record/attribute_methods/before_type_cast.rb +2 -1
  43. data/lib/active_record/attribute_methods/dirty.rb +8 -22
  44. data/lib/active_record/attribute_methods/primary_key.rb +1 -7
  45. data/lib/active_record/attribute_methods/read.rb +55 -28
  46. data/lib/active_record/attribute_methods/serialization.rb +12 -33
  47. data/lib/active_record/attribute_methods/time_zone_conversion.rb +1 -13
  48. data/lib/active_record/attribute_methods/write.rb +37 -12
  49. data/lib/active_record/autosave_association.rb +207 -207
  50. data/lib/active_record/base.rb +5 -1
  51. data/lib/active_record/callbacks.rb +2 -2
  52. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +2 -7
  53. data/lib/active_record/connection_adapters/abstract/database_statements.rb +11 -22
  54. data/lib/active_record/connection_adapters/abstract/query_cache.rb +12 -14
  55. data/lib/active_record/connection_adapters/abstract/quoting.rb +1 -5
  56. data/lib/active_record/connection_adapters/abstract/savepoints.rb +21 -0
  57. data/lib/active_record/connection_adapters/abstract/schema_creation.rb +84 -0
  58. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +9 -8
  59. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +52 -83
  60. data/lib/active_record/connection_adapters/abstract/transaction.rb +0 -5
  61. data/lib/active_record/connection_adapters/abstract_adapter.rb +14 -97
  62. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +58 -60
  63. data/lib/active_record/connection_adapters/column.rb +1 -35
  64. data/lib/active_record/connection_adapters/connection_specification.rb +2 -2
  65. data/lib/active_record/connection_adapters/mysql2_adapter.rb +3 -4
  66. data/lib/active_record/connection_adapters/mysql_adapter.rb +16 -15
  67. data/lib/active_record/connection_adapters/postgresql/array_parser.rb +24 -18
  68. data/lib/active_record/connection_adapters/postgresql/cast.rb +20 -16
  69. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +23 -43
  70. data/lib/active_record/connection_adapters/postgresql/oid.rb +19 -12
  71. data/lib/active_record/connection_adapters/postgresql/quoting.rb +28 -23
  72. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +8 -30
  73. data/lib/active_record/connection_adapters/postgresql_adapter.rb +92 -75
  74. data/lib/active_record/connection_adapters/schema_cache.rb +8 -29
  75. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +31 -64
  76. data/lib/active_record/connection_handling.rb +2 -2
  77. data/lib/active_record/core.rb +22 -43
  78. data/lib/active_record/counter_cache.rb +7 -7
  79. data/lib/active_record/enum.rb +100 -0
  80. data/lib/active_record/errors.rb +10 -5
  81. data/lib/active_record/fixture_set/file.rb +2 -1
  82. data/lib/active_record/fixtures.rb +171 -74
  83. data/lib/active_record/inheritance.rb +16 -22
  84. data/lib/active_record/integration.rb +52 -1
  85. data/lib/active_record/locking/optimistic.rb +7 -2
  86. data/lib/active_record/locking/pessimistic.rb +1 -1
  87. data/lib/active_record/log_subscriber.rb +5 -12
  88. data/lib/active_record/migration.rb +62 -46
  89. data/lib/active_record/migration/command_recorder.rb +7 -13
  90. data/lib/active_record/model_schema.rb +7 -14
  91. data/lib/active_record/nested_attributes.rb +10 -8
  92. data/lib/active_record/no_touching.rb +52 -0
  93. data/lib/active_record/null_relation.rb +3 -3
  94. data/lib/active_record/persistence.rb +16 -34
  95. data/lib/active_record/querying.rb +14 -12
  96. data/lib/active_record/railtie.rb +0 -50
  97. data/lib/active_record/railties/databases.rake +12 -15
  98. data/lib/active_record/readonly_attributes.rb +0 -6
  99. data/lib/active_record/reflection.rb +189 -75
  100. data/lib/active_record/relation.rb +69 -94
  101. data/lib/active_record/relation/batches.rb +57 -23
  102. data/lib/active_record/relation/calculations.rb +36 -43
  103. data/lib/active_record/relation/delegation.rb +54 -39
  104. data/lib/active_record/relation/finder_methods.rb +107 -62
  105. data/lib/active_record/relation/merger.rb +7 -20
  106. data/lib/active_record/relation/predicate_builder.rb +57 -38
  107. data/lib/active_record/relation/predicate_builder/array_handler.rb +29 -0
  108. data/lib/active_record/relation/predicate_builder/relation_handler.rb +13 -0
  109. data/lib/active_record/relation/query_methods.rb +110 -98
  110. data/lib/active_record/relation/spawn_methods.rb +1 -2
  111. data/lib/active_record/result.rb +45 -6
  112. data/lib/active_record/runtime_registry.rb +5 -0
  113. data/lib/active_record/sanitization.rb +6 -8
  114. data/lib/active_record/schema_dumper.rb +16 -5
  115. data/lib/active_record/schema_migration.rb +24 -25
  116. data/lib/active_record/scoping/default.rb +5 -18
  117. data/lib/active_record/scoping/named.rb +8 -29
  118. data/lib/active_record/store.rb +56 -28
  119. data/lib/active_record/tasks/database_tasks.rb +8 -4
  120. data/lib/active_record/timestamp.rb +4 -4
  121. data/lib/active_record/transactions.rb +8 -10
  122. data/lib/active_record/validations/presence.rb +1 -1
  123. data/lib/active_record/validations/uniqueness.rb +1 -6
  124. data/lib/active_record/version.rb +1 -1
  125. data/lib/rails/generators/active_record.rb +2 -8
  126. data/lib/rails/generators/active_record/migration.rb +18 -0
  127. data/lib/rails/generators/active_record/migration/migration_generator.rb +4 -0
  128. data/lib/rails/generators/active_record/model/model_generator.rb +4 -0
  129. metadata +32 -45
  130. data/lib/active_record/associations/has_and_belongs_to_many_association.rb +0 -65
  131. data/lib/active_record/associations/preloader/has_and_belongs_to_many.rb +0 -60
  132. data/lib/active_record/tasks/firebird_database_tasks.rb +0 -56
  133. data/lib/active_record/tasks/oracle_database_tasks.rb +0 -45
  134. data/lib/active_record/tasks/sqlserver_database_tasks.rb +0 -48
  135. data/lib/active_record/test_case.rb +0 -102
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ae43dd1ef6e205033ec72d38b8d3b6ab7b604684
4
- data.tar.gz: f163d6b09dea15d4333c978592a61e40089532fe
3
+ metadata.gz: 47c969d242da2dd41909dde035519bda9ae052d2
4
+ data.tar.gz: 161da4cf5078bc21183602281a927fcfc037ed1c
5
5
  SHA512:
6
- metadata.gz: feb23693186e93a56685ad58fd1ea6ac5f91b69f7f114c4c15c7f5dc4b9ac9ac5011360f61d7d073bae8bc61e3afc5c7e3b8b2482b4b72ed31e73d10ea8183e5
7
- data.tar.gz: 1a4d52daeaf706cbcce8fae899ec0c5b9ac7ade9b7ab1fb878eb3876d02db1c7c5f2f48e37ddd33b598c01ea6722b565ad5f217f77ff6352d1c8234a5d2d1741
6
+ metadata.gz: 33a8969b0e64f955f5c799331daf6d559c22282d0e1bde5032aed25466ca52afb0cb5438704692bbbe520e5f3a4a5ff02475963c8b81905590cc82084489edbe
7
+ data.tar.gz: 72d64ad26ffde56d6e58c609a97bf1dca7a8cc32278f1e2610138754821805b0b04483111053202b57151881318715ddd8becf34ba75eef7ac108ba3d917cd2e
@@ -1,3196 +1,1241 @@
1
- ## Rails 4.0.13 (January 6, 2015) ##
1
+ * `Relation` no longer has mutator methods like `#map!` and `#delete_if`. Convert
2
+ to an `Array` by calling `#to_a` before using these methods.
2
3
 
3
- * Renaming a table in pg also renames the primary key index.
4
+ It intends to prevent odd bugs and confusion in code that call mutator
5
+ methods directly on the `Relation`.
4
6
 
5
- Fixes #12856
6
-
7
- *Sean Griffin*
7
+ Example:
8
8
 
9
- * Make it possible to access fixtures excluded by a `default_scope`.
9
+ # Instead of this
10
+ Author.where(name: 'Hank Moody').compact!
10
11
 
11
- *Yves Senn*
12
+ # Now you have to do this
13
+ authors = Author.where(name: 'Hank Moody').to_a
14
+ authors.compact!
12
15
 
13
- * `timestamps` and `add_timestamps` passes additional options along.
14
- (like `null: false`)
16
+ *Lauro Caetano*
15
17
 
16
- Closes #17624.
18
+ * Better support for `where()` conditions that use a `belongs_to`
19
+ association name.
17
20
 
18
- *Yves Senn*
21
+ Using the name of an association in `where` previously worked only
22
+ if the value was a single `ActiveRecord::Base` object. e.g.
19
23
 
24
+ Post.where(author: Author.first)
20
25
 
21
- ## Rails 4.0.12 (November 16, 2014) ##
26
+ Any other values, including `nil`, would cause invalid SQL to be
27
+ generated. This change supports arguments in the `where` query
28
+ conditions where the key is a `belongs_to` association name and the
29
+ value is `nil`, an `Array` of `ActiveRecord::Base` objects, or an
30
+ `ActiveRecord::Relation` object.
22
31
 
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.
32
+ class Post < ActiveRecord::Base
33
+ belongs_to :author
34
+ end
26
35
 
27
- *Ben Woosley*
36
+ `nil` value finds records where the association is not set:
28
37
 
38
+ Post.where(author: nil)
39
+ # SELECT "posts".* FROM "posts" WHERE "posts"."author_id" IS NULL
29
40
 
30
- ## Rails 4.0.11.1 (November 19, 2014) ##
41
+ `Array` values find records where the association foreign key
42
+ matches the ids of the passed ActiveRecord models, resulting
43
+ in the same query as `Post.where(author_id: [1,2])`:
31
44
 
32
- *No changes*
45
+ authors_array = [Author.find(1), Author.find(2)]
46
+ Post.where(author: authors_array)
47
+ # SELECT "posts".* FROM "posts" WHERE "posts"."author_id" IN (1, 2)
33
48
 
49
+ `ActiveRecord::Relation` values find records using the same
50
+ query as `Post.where(author_id: Author.where(last_name: "Emde"))`
34
51
 
35
- ## Rails 4.0.11 (September 11, 2014) ##
52
+ Post.where(author: Author.where(last_name: "Emde"))
53
+ # SELECT "posts".* FROM "posts"
54
+ # WHERE "posts"."author_id" IN (
55
+ # SELECT "authors"."id" FROM "authors"
56
+ # WHERE "authors"."last_name" = 'Emde')
36
57
 
37
- *No changes*
58
+ Polymorphic `belongs_to` associations will continue to be handled
59
+ appropriately, with the polymorphic `association_type` field added
60
+ to the query to match the base class of the value. This feature
61
+ previously only worked when the value was a single `ActveRecord::Base`.
38
62
 
63
+ class Post < ActiveRecord::Base
64
+ belongs_to :author, polymorphic: true
65
+ end
39
66
 
40
- ## Rails 4.0.10 (September 11, 2014) ##
67
+ Post.where(author: Author.where(last_name: "Emde"))
68
+ # Generates a query similar to:
69
+ Post.where(author_id: Author.where(last_name: "Emde"), author_type: "Author")
41
70
 
42
- * Fixed a regression where whitespaces were stripped from DISTINCT queries in
43
- PostgreSQL.
71
+ *Martin Emde*
44
72
 
45
- *Agis Anastasopoulos*
73
+ * Respect temporary option when dropping tables with MySQL.
46
74
 
47
- Fixes #16623.
75
+ Normal DROP TABLE also works, but commits the transaction.
48
76
 
49
- * Fix regression on after_commit that didn't fire when having nested transactions.
77
+ drop_table :temporary_table, temporary: true
50
78
 
51
- Fixes #16425
79
+ *Cody Cutrer*
52
80
 
53
- *arthurnn*
81
+ * Add option to create tables from a query.
54
82
 
55
- * Define `id_was` to get the previous value of the primary key.
83
+ create_table(:long_query, temporary: true,
84
+ as: "SELECT * FROM orders INNER JOIN line_items ON order_id=orders.id")
56
85
 
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.
86
+ Generates:
61
87
 
62
- Fixes #16413.
88
+ CREATE TEMPORARY TABLE long_query AS
89
+ SELECT * FROM orders INNER JOIN line_items ON order_id=orders.id
63
90
 
64
- *Rafael Mendonça França*
91
+ *Cody Cutrer*
65
92
 
66
- * Fixed error in `reset_counters` when associations have `select` scope.
67
- (Call to `count` generates invalid SQL.)
93
+ * `db:test:clone` and `db:test:prepare` must load Rails environment.
68
94
 
69
- *Cade Truitt*
95
+ `db:test:clone` and `db:test:prepare` use `ActiveRecord::Base`. configurations,
96
+ so we need to load the Rails environment, otherwise the config wont be in place.
70
97
 
71
- * After a successful `reload`, `new_record?` is always false.
98
+ *arthurnn*
72
99
 
73
- Fixes #12101.
100
+ * Use the right column to type cast grouped calculations with custom expressions.
74
101
 
75
- *Matthew Draper*
102
+ Fixes #13230.
76
103
 
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.
104
+ Example:
80
105
 
81
- *Sean Griffin*
106
+ # Before
107
+ Account.group(:firm_name).sum('0.01 * credit_limit')
108
+ # => { '37signals' => '0.5' }
82
109
 
83
- * Correctly extract IPv6 addresses from `DATABASE_URI`: the square brackets
84
- are part of the URI structure, not the actual host.
110
+ # After
111
+ Account.group(:firm_name).sum('0.01 * credit_limit')
112
+ # => { '37signals' => 0.5 }
85
113
 
86
- Fixes #15705.
114
+ *Paul Nikitochkin*
87
115
 
88
- *Andy Bakun*, *Aaron Stone*
116
+ * Polymorphic `belongs_to` associations with the `touch: true` option set update the timestamps of
117
+ the old and new owner correctly when moved between owners of different types.
89
118
 
90
- * Don't error when quoting user defined types in PostgreSQL.
119
+ Example:
91
120
 
92
- Fixes #15697.
121
+ class Rating < ActiveRecord::Base
122
+ belongs_to :rateable, polymorphic: true, touch: true
123
+ end
93
124
 
94
- *Sean Griffin*
125
+ rating = Rating.create rateable: Song.find(1)
126
+ rating.update_attributes rateable: Book.find(2) # => timestamps of Song(1) and Book(2) are updated
95
127
 
96
- * `ActiveRecord::FinderMethods.find` with block can handle proc parameter as
97
- `Enumerable#find` does.
128
+ *Severin Schoepke*
98
129
 
99
- Fixes #15382.
130
+ * Improve formatting of migration exception messages: make them easier to read
131
+ with line breaks before/after, and improve the error for pending migrations.
100
132
 
101
- *James Yang*
133
+ *John Bachir*
102
134
 
103
- * `ActiveRecord::SchemaMigration` has no primary key regardless of the
104
- `primary_key_prefix_type` configuration.
135
+ * Fix `last` with `offset` to return the proper record instead of always the last one.
105
136
 
106
- Fixes #15051.
137
+ Example:
107
138
 
108
- *JoseLuis Torres*, *Yves Senn*
139
+ Model.offset(4).last
140
+ # => returns the 4th record from the end.
109
141
 
110
- * `rake db:migrate:status` works with legacy migration numbers like `00018_xyz.rb`.
142
+ Fixes #7441.
111
143
 
112
- Fixes #15538.
144
+ *kostya*, *Lauro Caetano*
113
145
 
114
- *Yves Senn*
146
+ * `type_to_sql` returns a `String` for unmapped columns. This fixes an error
147
+ when using unmapped array types in PG
115
148
 
116
- * Fixed `columns_for_distinct` of postgresql adapter to work correctly
117
- with orders without sort direction modifiers.
149
+ Example:
118
150
 
119
- *Nikolay Kondratyev*
151
+ change_colum :table, :column, :bigint, array: true
120
152
 
121
- * `rake railties:install:migrations` respects the order of railties.
153
+ Fixes #13146.
122
154
 
123
- *Arun Agrawal*
155
+ *Jens Fahnenbruck*, *Yves Senn*
124
156
 
157
+ * Fix `QueryCache` to work with nested blocks, so that it will only clear the existing cache
158
+ after leaving the outer block instead of clearing it right after the inner block is finished.
125
159
 
126
- ## Rails 4.0.9 (August 18, 2014) ##
160
+ *Vipul A M*
127
161
 
128
- * Check attributes passed to `create_with` and `where`.
162
+ * The ERB in fixture files is no longer evaluated in the context of the main
163
+ object. Helper methods used by multiple fixtures should be defined on the
164
+ class object returned by `ActiveRecord::FixtureSet.context_class`.
129
165
 
130
- Fixes CVE-2014-3514.
166
+ *Victor Costan*
131
167
 
132
- *Rafael Mendonça França*
168
+ * Previously, the `has_one` macro incorrectly accepted the `counter_cache`
169
+ option, but never actually supported it. Now it will raise an `ArgumentError`
170
+ when using `has_one` with `counter_cache`.
133
171
 
172
+ *Godfrey Chan*
134
173
 
135
- ## Rails 4.0.8 (July 2, 2014) ##
174
+ * Implement `rename_index` natively for MySQL >= 5.7.
136
175
 
137
- * Fix regression added from the latest security fix.
176
+ *Cody Cutrer*
138
177
 
139
- *Sean Griffin*, *Matthew Draper*
178
+ * Fix bug when validating the uniqueness of an aliased attribute.
140
179
 
180
+ Fixes #12402.
141
181
 
142
- ## Rails 4.0.7 (July 2, 2014) ##
182
+ *Lauro Caetano*
143
183
 
144
- * Fix SQL Injection Vulnerability in 'range' quoting.
184
+ * Update counter cache on a `has_many` relationship regardless of default scope.
145
185
 
146
- Fixes CVE-2014-3483
186
+ Fix #12952.
147
187
 
148
- *Rafael Mendonça França*
188
+ *Uku Taht*
149
189
 
190
+ * `rename_index` adds the new index before removing the old one. This allows to
191
+ rename indexes on columns with a foreign key and prevents the following error:
150
192
 
151
- ## Rails 4.0.6 (June 26, 2014) ##
193
+ Cannot drop index 'index_engines_on_car_id': needed in a foreign key constraint
152
194
 
153
- * Fixed the inferred table name of a has_and_belongs_to_many auxiliar
154
- table inside a schema.
195
+ *Cody Cutrer*, *Yves Senn*
155
196
 
156
- Fixes #14824
197
+ * Raise `ActiveRecord::RecordNotDestroyed` when a replaced child marked with `dependent: destroy` fails to be destroyed.
157
198
 
158
- *Eric Chahin*
199
+ Fix #12812
159
200
 
160
- * Fix bug that added `table_name_prefix` and `table_name_suffix` to
161
- extension names in PostgreSQL when migrating.
201
+ *Brian Thomas Storti*
162
202
 
163
- *Joao Carlos*
203
+ * Fix validation on uniqueness of empty association.
164
204
 
165
- * `ActiveRecord::Relation::Merger#filter_binds` now compares equivalent symbols and
166
- strings in column names as equal.
205
+ *Evgeny Li*
167
206
 
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.
207
+ * Make `ActiveRecord::Relation#unscope` affect relations it is merged in to.
171
208
 
172
- *Nat Budin*
209
+ *Jon Leighton*
173
210
 
174
- * Calling `delete_all` on an unloaded `CollectionProxy` no longer
175
- generates a SQL statement containing each id of the collection:
211
+ * Use strings to represent non-string `order_values`.
176
212
 
177
- Before:
213
+ *Yves Senn*
178
214
 
179
- DELETE FROM `model` WHERE `model`.`parent_id` = 1
180
- AND `model`.`id` IN (1, 2, 3...)
215
+ * Checks to see if the record contains the foreign key to set the inverse automatically.
181
216
 
182
- After:
217
+ *Edo Balvers*
183
218
 
184
- DELETE FROM `model` WHERE `model`.`parent_id` = 1
219
+ * Added `ActiveRecord::Base.to_param` for convenient "pretty" URLs derived from a model's attribute or method.
185
220
 
186
- *Eileen M. Uchitelle*, *Aaron Patterson*
221
+ Example:
187
222
 
188
- * Fix `stored_attributes` to correctly merge the details of stored
189
- attributes defined in parent classes.
223
+ class User < ActiveRecord::Base
224
+ to_param :name
225
+ end
190
226
 
191
- Fixes #14672.
227
+ user = User.find_by(name: 'Fancy Pants')
228
+ user.id # => 123
229
+ user.to_param # => "123-fancy-pants"
192
230
 
193
- *Brad Bennett*, *Jessica Yao*, *Lakshmi Parthasarathy*
231
+ *Javan Makhmali*
194
232
 
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`.
233
+ * Added `ActiveRecord::Base.no_touching`, which allows ignoring touch on models.
198
234
 
199
- *Yves Senn*
235
+ Example:
200
236
 
201
- * `change_column_default` allows `[]` as argument to `change_column_default`.
237
+ Post.no_touching do
238
+ Post.first.touch
239
+ end
202
240
 
203
- Fixes #11586.
241
+ *Sam Stephenson*, *Damien Mathieu*
204
242
 
205
- *Yves Senn*
243
+ * Prevent the counter cache from being decremented twice when destroying
244
+ a record on a `has_many :through` association.
206
245
 
207
- * Fixed has_and_belongs_to_many's CollectionAssociation size calculation.
246
+ Fixes #11079.
208
247
 
209
- has_and_belongs_to_many should not include new records as part of
210
- `#count_records` as new records are already counted.
248
+ *Dmitry Dedov*
211
249
 
212
- Fixes #14914.
250
+ * Unify boolean type casting for `MysqlAdapter` and `Mysql2Adapter`.
251
+ `type_cast` will return `1` for `true` and `0` for `false`.
213
252
 
214
- *Fred Wu*
253
+ Fixes #11119.
215
254
 
216
- * Stringify all variables keys of MySQL connection configuration.
255
+ *Adam Williams*, *Yves Senn*
217
256
 
218
- When `sql_mode` variable for MySQL adapters set in configuration as `String`
219
- was ignored and overwritten by strict mode option.
257
+ * Fix bug where `has_one` association record update result in crash, when replaced with itself.
220
258
 
221
- Fixes #14895.
259
+ Fixes #12834.
222
260
 
223
- *Paul Nikitochkin*
261
+ *Denis Redozubov*, *Sergio Cambra*
224
262
 
225
- * Ensure SQLite3 statements are closed on errors.
263
+ * Log bind variables after they are type casted. This makes it more
264
+ transparent what values are actually sent to the database.
226
265
 
227
- Fixes: #13631.
266
+ irb(main):002:0> Event.find("im-no-integer")
267
+ # Before: ... WHERE "events"."id" = $1 LIMIT 1 [["id", "im-no-integer"]]
268
+ # After: ... WHERE "events"."id" = $1 LIMIT 1 [["id", 0]]
228
269
 
229
- *Timur Alperovich*
270
+ *Yves Senn*
230
271
 
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.
272
+ * Fix uninitialized constant `TransactionState` error when `Marshall.load` is used on an Active Record result.
233
273
 
234
- Backports #14154.
274
+ Fixes #12790.
235
275
 
236
- *Matt Jones*
276
+ *Jason Ayre*
237
277
 
238
- * Fix name collision with `Array#select!` with `Relation#select!`.
278
+ * `.unscope` now removes conditions specified in `default_scope`.
239
279
 
240
- Fixes #14752.
280
+ *Jon Leighton*
241
281
 
242
- *Earl St Sauver*
282
+ * Added `ActiveRecord::QueryMethods#rewhere` which will overwrite an existing, named where condition.
243
283
 
244
- * When a destroyed record is duped, the dup is not `destroyed?`.
284
+ Examples:
245
285
 
246
- *Kuldeep Aggarwal*
286
+ Post.where(trashed: true).where(trashed: false) #=> WHERE `trashed` = 1 AND `trashed` = 0
287
+ Post.where(trashed: true).rewhere(trashed: false) #=> WHERE `trashed` = 0
288
+ Post.where(active: true).where(trashed: true).rewhere(trashed: false) #=> WHERE `active` = 1 AND `trashed` = 0
247
289
 
248
- * Fixed has_many association to make it support irregular inflections.
290
+ *DHH*
249
291
 
250
- Fixes #8928.
292
+ * Extend `ActiveRecord::Base#cache_key` to take an optional list of timestamp attributes of which the highest will be used.
251
293
 
252
- *arthurnn*, *Javier Goizueta*
294
+ Example:
253
295
 
254
- * Fixed a problem where count used with a grouping was not returning a Hash.
296
+ # last_reviewed_at will be used, if that's more recent than updated_at, or vice versa
297
+ Person.find(5).cache_key(:updated_at, :last_reviewed_at)
255
298
 
256
- Fixes #14721.
299
+ *DHH*
257
300
 
258
- *Eric Chahin*
301
+ * Added `ActiveRecord::Base#enum` for declaring enum attributes where the values map to integers in the database, but can be queried by name.
259
302
 
260
- * Do not quote uuid default value on `change_column`.
303
+ Example:
261
304
 
262
- Fixes #14604.
305
+ class Conversation < ActiveRecord::Base
306
+ enum status: [:active, :archived]
307
+ end
263
308
 
264
- *Eric Chahin*
309
+ Conversation::STATUS # => { active: 0, archived: 1 }
265
310
 
266
- * The comparison between `Relation` and `CollectionProxy` should be consistent.
311
+ # conversation.update! status: 0
312
+ conversation.active!
313
+ conversation.active? # => true
314
+ conversation.status # => "active"
267
315
 
268
- Example:
316
+ # conversation.update! status: 1
317
+ conversation.archived!
318
+ conversation.archived? # => true
319
+ conversation.status # => "archived"
269
320
 
270
- author.posts == Post.where(author_id: author.id)
271
- # => true
272
- Post.where(author_id: author.id) == author.posts
273
- # => true
321
+ # conversation.update! status: 1
322
+ conversation.status = :archived
274
323
 
275
- Fixes #13506.
324
+ *DHH*
276
325
 
277
- *Lauro Caetano*
326
+ * `ActiveRecord::Base#attribute_for_inspect` now truncates long arrays (more than 10 elements).
278
327
 
279
- * PostgreSQL adapter only warns once for every missing OID per connection.
328
+ *Jan Bernacki*
280
329
 
281
- Fixes #14275.
330
+ * Allow for the name of the `schema_migrations` table to be configured.
282
331
 
283
- *Matthew Draper*, *Yves Senn*
332
+ *Jerad Phelps*
284
333
 
285
- * Fix insertion of records via `has_many :through` association with scope.
334
+ * Do not add to scope includes values from through associations.
335
+ Fixed bug when providing `includes` in through association scope, and fetching targets.
286
336
 
287
- Fixes #3548.
337
+ Example:
288
338
 
289
- *Ivan Antropov*
339
+ class Vendor < ActiveRecord::Base
340
+ has_many :relationships, -> { includes(:user) }
341
+ has_many :users, through: :relationships
342
+ end
290
343
 
291
- * Make possible to have an association called `records`.
344
+ vendor = Vendor.first
292
345
 
293
- Fixes #11645.
346
+ # Before
294
347
 
295
- *prathamesh-sonpatki*
348
+ vendor.users.to_a # => Raises exception: not found `:user` for `User`
296
349
 
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
+ # After
301
351
 
302
- Fixes #14003.
352
+ vendor.users.to_a # => No exception is raised
303
353
 
304
- *Jefferson Lai*
354
+ Fixes #12242, #9517, #10240.
305
355
 
306
- * Fixed error when using `with_options` with lambda.
356
+ *Paul Nikitochkin*
307
357
 
308
- Fixes #9805.
358
+ * Type cast json values on write, so that the value is consistent
359
+ with reading from the database.
309
360
 
310
- *Lauro Caetano*
361
+ Example:
311
362
 
312
- * Fixed error when specifying a non-empty default value on a PostgreSQL array column.
363
+ x = JsonDataType.new tags: {"string" => "foo", :symbol => :bar}
313
364
 
314
- Fixes #10613.
365
+ # Before:
366
+ x.tags # => {"string" => "foo", :symbol => :bar}
315
367
 
316
- *Luke Steensen*
368
+ # After:
369
+ x.tags # => {"string" => "foo", "symbol" => "bar"}
317
370
 
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.
371
+ *Severin Schoepke*
320
372
 
321
- Fixes #14393.
373
+ * `ActiveRecord::Store` works together with PG `hstore` columns.
322
374
 
323
- *Chris Finne*
375
+ Fixes #12452.
324
376
 
325
- * `rake db:structure:dump` only dumps schema information if the schema
326
- migration table exists.
377
+ *Yves Senn*
327
378
 
328
- Fixes #14217.
379
+ * Fix bug where `ActiveRecord::Store` used a global `Hash` to keep track of
380
+ all registered `stored_attributes`. Now every subclass of
381
+ `ActiveRecord::Base` has it's own `Hash`.
329
382
 
330
383
  *Yves Senn*
331
384
 
332
- * Fix counter cache when association uses a `class_name`.
385
+ * Save `has_one` association when primary key is manually set.
333
386
 
334
- Fixes #14369.
387
+ Fixes #12302.
335
388
 
336
- *arthurnn*
389
+ *Lauro Caetano*
337
390
 
338
- * Add support for `Relation` be passed as parameter on `QueryCache#select_all`.
391
+ * Allow any version of BCrypt when using `has_secure_password`.
339
392
 
340
- Fixes #14361.
393
+ *Mike Perham*
341
394
 
342
- *arthurnn*
395
+ * Sub-query generated for `Relation` passed as array condition did not take in account
396
+ bind values and have invalid syntax.
343
397
 
398
+ Generate sub-query with inline bind values.
344
399
 
345
- ## Rails 4.0.5 (May 6, 2014) ##
400
+ Fixes #12586.
346
401
 
347
- *No changes*
402
+ *Paul Nikitochkin*
348
403
 
404
+ * Fix a bug where rake db:structure:load crashed when the path contained
405
+ spaces.
349
406
 
350
- ## Rails 4.0.4 (March 14, 2014) ##
407
+ *Kevin Mook*
351
408
 
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.
409
+ * `ActiveRecord::QueryMethods#unscope` unscopes negative equality
355
410
 
356
- *Alan Kennedy*
411
+ Allows you to call `#unscope` on a relation with negative equality
412
+ operators, i.e. `Arel::Nodes::NotIn` and `Arel::Nodes::NotEqual` that have
413
+ been generated through the use of `where.not`.
357
414
 
358
- * Fixed STI classes not defining an attribute method if there is a
359
- conflicting private method defined on its ancestors.
415
+ *Eric Hankins*
360
416
 
361
- Fixes #11569.
417
+ * Raise an exception when model without primary key calls `.find_with_ids`.
362
418
 
363
- *Godfrey Chan*
419
+ *Shimpei Makimoto*
364
420
 
365
- * Fix validation on uniqueness of empty association.
421
+ * Make `Relation#empty?` use `exists?` instead of `count`.
366
422
 
367
- *Evgeny Li*
423
+ *Szymon Nowak*
368
424
 
369
- * Perform necessary deeper encoding when hstore is inside an array.
425
+ * `rake db:structure:dump` no longer crashes when the port was specified as `Fixnum`.
370
426
 
371
- Fixes #11135.
427
+ *Kenta Okamoto*
372
428
 
373
- *Josh Goodall*, *Genadi Samokovarov*
429
+ * `NullRelation#pluck` takes a list of columns
374
430
 
375
- * Properly detect if a connection is still active before using it
376
- in multi-threaded environments.
431
+ The method signature in `NullRelation` was updated to mimic that in
432
+ `Calculations`.
377
433
 
378
- Fixes #12867.
434
+ *Derek Prior*
379
435
 
380
- *Kevin Casey*, *Matthew Draper*, *William (B.J.) Snow Orvis*
436
+ * `scope_chain` should not be mutated for other reflections.
381
437
 
382
- * When inverting add_index use the index name if present instead of
383
- the columns.
438
+ Currently `scope_chain` uses same array for building different
439
+ `scope_chain` for different associations. During processing
440
+ these arrays are sometimes mutated and because of in-place
441
+ mutation the changed `scope_chain` impacts other reflections.
384
442
 
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.
443
+ Fix is to dup the value before adding to the `scope_chain`.
388
444
 
389
- The inversion of add_index will now drop the index by its name if
390
- it is present.
445
+ Fixes #3882.
391
446
 
392
- *Hubert Dąbrowski*
447
+ *Neeraj Singh*
393
448
 
394
- * Make sure transaction state gets reset after a commit operation on the record.
449
+ * Prevent the inversed association from being reloaded on save.
395
450
 
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.
451
+ Fixes #9499.
398
452
 
399
- Fixes #12566.
453
+ *Dmitry Polushkin*
400
454
 
401
- *arthurnn*
455
+ * Generate subquery for `Relation` if it passed as array condition for `where`
456
+ method.
402
457
 
403
- * PostgreSQL implementation of `SchemaStatements#index_name_exists?`.
458
+ Example:
404
459
 
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.
460
+ # Before
461
+ Blog.where('id in (?)', Blog.where(id: 1))
462
+ # => SELECT "blogs".* FROM "blogs" WHERE "blogs"."id" = 1
463
+ # => SELECT "blogs".* FROM "blogs" WHERE (id IN (1))
408
464
 
409
- Fixes #11018.
465
+ # After
466
+ Blog.where('id in (?)', Blog.where(id: 1).select(:id))
467
+ # => SELECT "blogs".* FROM "blogs"
468
+ # WHERE "blogs"."id" IN (SELECT "blogs"."id" FROM "blogs" WHERE "blogs"."id" = 1)
410
469
 
411
- *Jonathan Baudanza*
470
+ Fixes #12415.
412
471
 
413
- * Parsing PostgreSQL arrays with empty strings now works correctly.
472
+ *Paul Nikitochkin*
414
473
 
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.
474
+ * For missed association exception message
475
+ which is raised in `ActiveRecord::Associations::Preloader` class
476
+ added owner record class name in order to simplify to find problem code.
419
477
 
420
- Fixes #13907.
478
+ *Paul Nikitochkin*
421
479
 
422
- *Maurício Linhares*
480
+ * `has_and_belongs_to_many` is now transparently implemented in terms of
481
+ `has_many :through`. Behavior should remain the same, if not, it is a bug.
423
482
 
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.
483
+ * `create_savepoint`, `rollback_to_savepoint` and `release_savepoint` accept
484
+ a savepoint name.
427
485
 
428
- Fixes #7538, #12017, #13731, #12056.
486
+ *Yves Senn*
429
487
 
430
- *arthurnn*
488
+ * Make `next_migration_number` accessible for third party generators.
431
489
 
432
- * Correctly send an user provided statement to a `lock!()` call.
490
+ *Yves Senn*
433
491
 
434
- person.lock! 'FOR SHARE NOWAIT'
435
- # Before: SELECT * ... LIMIT 1 FOR UPDATE
436
- # After: SELECT * ... LIMIT 1 FOR SHARE NOWAIT
492
+ * Objects instantiated using a null relationship will now retain the
493
+ attributes of the where clause.
437
494
 
438
- Fixes #13788.
495
+ Fixes #11676, #11675, #11376.
439
496
 
440
- *Maurício Linhares*
497
+ *Paul Nikitochkin*, *Peter Brown*, *Nthalk*
441
498
 
442
- * Active Record objects can now be correctly dumped, loaded and dumped again without issues.
499
+ * Fixed `ActiveRecord::Associations::CollectionAssociation#find`
500
+ when using `has_many` association with `:inverse_of` and finding an array of one element,
501
+ it should return an array of one element too.
443
502
 
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.
503
+ *arthurnn*
449
504
 
450
- Fixes #13861.
505
+ * Callbacks on has_many should access the in memory parent if a inverse_of is set.
451
506
 
452
- *Maurício Linhares*
507
+ *arthurnn*
453
508
 
454
- * `has_one` and `belongs_to` accessors don't add ORDER BY to the queries anymore.
509
+ * `ActiveRecord::ConnectionAdapters.string_to_time` respects
510
+ string with timezone (e.g. Wed, 04 Sep 2013 20:30:00 JST).
455
511
 
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.
512
+ Fixes #12278.
460
513
 
461
- Fixes #12623.
514
+ *kennyj*
462
515
 
463
- *Rafael Mendonça França*
516
+ * Calling `update_attributes` will now throw an `ArgumentError` whenever it
517
+ gets a `nil` argument. More specifically, it will throw an error if the
518
+ argument that it gets passed does not respond to to `stringify_keys`.
464
519
 
465
- * Fail early with "Primary key not included in the custom select clause"
466
- in `find_in_batches`.
520
+ Example:
467
521
 
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.
522
+ @my_comment.update_attributes(nil) # => raises ArgumentError
471
523
 
472
- *Alexander Balashov*
524
+ *John Wang*
473
525
 
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`).
526
+ * Deprecate `quoted_locking_column` method, which isn't used anywhere.
477
527
 
478
- Fixes #13744.
528
+ *kennyj*
479
529
 
480
- *Godfrey Chan*
530
+ * Migration dump UUID default functions to schema.rb.
481
531
 
482
- * Add back `#yaml_initialize` method for Syck deserialization
532
+ Fixes #10751.
483
533
 
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.
534
+ *kennyj*
488
535
 
489
- *Blake Mesdag*, *arthurnn*
536
+ * Fixed a bug in `ActiveRecord::Associations::CollectionAssociation#find_by_scan`
537
+ when using `has_many` association with `:inverse_of` option and UUID primary key.
490
538
 
491
- * Make `touch` fire the `after_commit` and `after_rollback` callbacks.
539
+ Fixes #10450.
492
540
 
493
- *Harry Brundage*
541
+ *kennyj*
494
542
 
495
- * Don't try to get the subclass if the inheritance column doesn't exist
543
+ * Fix: joins association, with defined in the scope block constraints by using several
544
+ where constraints and at least of them is not `Arel::Nodes::Equality`,
545
+ generates invalid SQL expression.
496
546
 
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.
547
+ Fixes #11963.
501
548
 
502
- *Ujjwal Thaakar*
549
+ *Paul Nikitochkin*
503
550
 
504
- * Fix bug in `becomes!` when changing from the base model to a STI sub-class.
551
+ * `CollectionAssociation#first`/`#last` (e.g. `has_many`) use a `LIMIT`ed
552
+ query to fetch results rather than loading the entire collection.
505
553
 
506
- Fixes #13272.
554
+ *Lann Martin*
507
555
 
508
- *the-web-dev*, *Yves Senn*
556
+ * Make possible to run SQLite rake tasks without the `Rails` constant defined.
509
557
 
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.
558
+ *Damien Mathieu*
512
559
 
513
- *Dylan Thacker-Smith*
560
+ * Allow Relation#from to accept other relations with bind values.
514
561
 
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.
562
+ *Ryan Wallace*
519
563
 
520
- Fixes #13577 and #13503.
564
+ * Fix inserts with prepared statements disabled.
521
565
 
522
- *Nishant Modak*, *Prathamesh Sonpatki*, *Rafael Mendonça França*
566
+ Fixes #12023.
523
567
 
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.
568
+ *Rafael Mendonça França*
526
569
 
527
- Fixes #13570.
570
+ * Setting a has_one association on a new record no longer causes an empty
571
+ transaction.
528
572
 
529
- *Thales Oliveira*
573
+ *Dylan Thacker-Smith*
530
574
 
531
- * Fix presence validator for association when the associated record responds to `to_a`.
575
+ * Fix `AR::Relation#merge` sometimes failing to preserve `readonly(false)` flag.
532
576
 
533
- *gmarik*
577
+ *thedarkone*
534
578
 
535
- * Fix bug in `belongs_to` association with `touch: true`.
536
- Associated records are no longer touched, when they are already destroyed.
579
+ * Re-use `order` argument pre-processing for `reorder`.
537
580
 
538
- Fixes #13445.
581
+ *Paul Nikitochkin*
539
582
 
540
- Example:
583
+ * Fix PredicateBuilder so polymorphic association keys in `where` clause can
584
+ accept objects other than direct descendants of `ActiveRecord::Base` (decorated
585
+ models, for example).
541
586
 
542
- # Given Comment has belongs_to :post, touch: true
543
- comment.post.destroy
544
- comment.destroy # no longer touches post
587
+ *Mikhail Dieterle*
545
588
 
546
- *Paul Nikitochkin*
589
+ * PostgreSQL adapter recognizes negative money values formatted with
590
+ parentheses (eg. `($1.25) # => -1.25`)).
591
+ Fixes #11899.
547
592
 
548
- * Fixed `update_column`, `update_columns`, and `update_all` to correctly serialize
549
- values for `array`, `hstore` and `json` column types in PostgreSQL.
593
+ *Yves Senn*
550
594
 
551
- Fixes #12261.
595
+ * Stop interpreting SQL 'string' columns as :string type because there is no
596
+ common STRING datatype in SQL.
552
597
 
553
- *Tadas Tamosauskas*, *Carlos Antonio da Silva*
598
+ *Ben Woosley*
554
599
 
555
- * Do not consider PostgreSQL array columns as number or text columns.
600
+ * `ActiveRecord::FinderMethods#exists?` returns `true`/`false` in all cases.
556
601
 
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:
602
+ *Xavier Noria*
560
603
 
561
- if column.number?
562
- !value.zero?
563
- end
604
+ * Assign inet/cidr attribute with `nil` value for invalid address.
564
605
 
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.
606
+ Example:
567
607
 
568
- Fixing this by ensuring that array columns in PostgreSQL never return
569
- true for number?/text? checks.
608
+ record = User.new
609
+ record.logged_in_from_ip # is type of an inet or a cidr
570
610
 
571
- *Carlos Antonio da Silva*
611
+ # Before:
612
+ record.logged_in_from_ip = 'bad ip address' # raise exception
572
613
 
573
- * Fix a bug when assigning an array containing string numbers to a
574
- PostgreSQL integer array column.
614
+ # After:
615
+ record.logged_in_from_ip = 'bad ip address' # do not raise exception
616
+ record.logged_in_from_ip # => nil
617
+ record.logged_in_from_ip_before_type_cast # => 'bad ip address'
575
618
 
576
- Fixes #13444.
619
+ *Paul Nikitochkin*
577
620
 
578
- Example:
621
+ * `add_to_target` now accepts a second optional `skip_callbacks` argument
579
622
 
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
623
+ If truthy, it will skip the :before_add and :after_add callbacks.
583
624
 
584
- *Damien Mathieu*
625
+ *Ben Woosley*
585
626
 
586
- * `db:test:clone` and `db:test:prepare` must load Rails environment.
627
+ * Fix interactions between `:before_add` callbacks and nested attributes
628
+ assignment of `has_many` associations, when the association was not
629
+ yet loaded:
587
630
 
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.
631
+ - A `:before_add` callback was being called when a nested attributes
632
+ assignment assigned to an existing record.
590
633
 
591
- *arthurnn*
634
+ - Nested Attributes assignment did not affect the record in the
635
+ association target when a `:before_add` callback triggered the
636
+ loading of the association
592
637
 
593
- * Use the right column to type cast grouped calculations with custom expressions.
638
+ *Jörg Schray*
594
639
 
595
- Fixes #13230.
640
+ * Allow enable_extension migration method to be revertible.
596
641
 
597
- Example:
642
+ *Eric Tipton*
598
643
 
599
- # Before
600
- Account.group(:firm_name).sum('0.01 * credit_limit')
601
- # => { '37signals' => '0.5' }
644
+ * Type cast hstore values on write, so that the value is consistent
645
+ with reading from the database.
602
646
 
603
- # After
604
- Account.group(:firm_name).sum('0.01 * credit_limit')
605
- # => { '37signals' => 0.5 }
647
+ Example:
606
648
 
607
- *Paul Nikitochkin*
649
+ x = Hstore.new tags: {"bool" => true, "number" => 5}
608
650
 
609
- * Support deprecated finder options when performing calculations
610
- on an association.
651
+ # Before:
652
+ x.tags # => {"bool" => true, "number" => 5}
611
653
 
612
- Fixes #13165.
654
+ # After:
655
+ x.tags # => {"bool" => "true", "number" => "5"}
613
656
 
614
- *Garth Smedley*, *Yves Senn*
657
+ *Yves Senn* , *Severin Schoepke*
615
658
 
616
- * `ActiveRecord::ConnectionAdapters.string_to_time` respects
617
- string with timezone (e.g. Wed, 04 Sep 2013 20:30:00 JST).
659
+ * Fix multidimensional PG arrays containing non-string items.
618
660
 
619
- Fixes #12278, #12459.
661
+ *Yves Senn*
620
662
 
621
- *kennyj*, *George Guimarães*
663
+ * Fixes bug when using includes combined with select, the select statement was overwritten.
622
664
 
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.
665
+ Fixes #11773.
625
666
 
626
- Example:
667
+ *Edo Balvers*
627
668
 
628
- class Rating < ActiveRecord::Base
629
- belongs_to :rateable, polymorphic: true, touch: true
630
- end
669
+ * Load fixtures from linked folders.
631
670
 
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
634
-
635
- *Severin Schoepke*
636
-
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`.
639
-
640
- Fixes #13146.
641
-
642
- Example:
643
-
644
- change_colum :table, :column, :bigint, array: true
645
-
646
- *Jens Fahnenbruck*, *Yves Senn*
647
-
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.
652
-
653
- *Godfrey Chan*
654
-
655
- * Update counter cache on a has_many relationship regardless of default scope
656
-
657
- Fix #12952.
658
-
659
- *Uku Taht*
660
-
661
- * Fix bug when validating the uniqueness of an aliased attribute.
662
-
663
- Fixes #12402.
664
-
665
- *Lauro Caetano*
666
-
667
- * Checks to see if the record contains the foreign key to set the inverse automatically.
668
-
669
- *Edo Balvers*
670
-
671
- * Prevent the counter cache from being decremented twice when destroying
672
- a record on a has_many :through association.
673
-
674
- Fixes #11079.
675
-
676
- *Dmitry Dedov*
677
-
678
- * Fix bug where has_one associaton record update result in crash, when replaced with itself.
679
-
680
- Fixes #12834.
681
-
682
- *Denis Redozubov*, *Sergio Cambra*
683
-
684
- * Fix uninitialized constant TransactionState error when Marshall.load is used on an Active Record result.
685
-
686
- Fixes #12790.
687
-
688
- *Jason Ayre*
689
-
690
- * Do not add to scope includes values from through associations.
691
- Fixed bug when providing `includes` in through association scope, and fetching targets.
692
-
693
- Example:
694
- class Vendor < ActiveRecord::Base
695
- has_many :relationships, -> { includes(:user) }
696
- has_many :users, through: :relationships
697
- end
698
-
699
- vendor = Vendor.first
700
-
701
- # Before
702
-
703
- vendor.users.to_a # => Raises exception: not found `:user` for `User`
704
-
705
- # After
706
-
707
- vendor.users.to_a # => No exception is raised
708
-
709
-
710
- Fixes #12242, #9517, #10240.
711
-
712
- *Paul Nikitochkin*
713
-
714
- * Save `has_one` association when primary key is manually set.
715
-
716
- Fixes #12302.
717
-
718
- *Lauro Caetano*
719
-
720
- * Allow any version of BCrypt when using `has_secury_password`.
721
-
722
- *Mike Perham*
723
-
724
- * Assign inet/cidr attribute with `nil` value for invalid address.
725
-
726
- Example:
727
-
728
- record = User.new
729
-
730
- record.logged_in_from_ip # is type of an inet or a cidr
731
-
732
- # Before:
733
- record.logged_in_from_ip = 'bad ip address' # raise exception
734
-
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'
739
-
740
- *Paul Nikitochkin*
741
-
742
- * `rake db:structure:dump` no longer crashes when the port was specified as `Fixnum`.
743
-
744
- *Kenta Okamoto*
745
-
746
- * Fix a bug where rake db:structure:load crashed when the path contained
747
- spaces.
748
-
749
- *Kevin Mook*
750
-
751
- * `ActiveRecord::QueryMethods#unscope` unscopes negative equality
752
-
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`.
756
-
757
- *Eric Hankins*
758
-
759
-
760
- ## Rails 4.0.3 (February 18, 2014) ##
761
-
762
- * Correctly escape PostgreSQL arrays.
763
-
764
- Fixes: CVE-2014-0080
765
-
766
-
767
- ## Rails 4.0.2 (December 02, 2013) ##
768
-
769
- *No changes*
770
-
771
-
772
- ## Rails 4.0.1 (November 01, 2013) ##
773
-
774
- * `NullRelation#pluck` takes a list of columns
775
-
776
- The method signature in `NullRelation` was updated to mimic that in
777
- `Calculations`.
778
-
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`.
1155
-
1156
- *Piotr Sarnacki*
1157
-
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*
2498
-
2499
- * PostgreSQL inet and cidr types are converted to `IPAddr` objects.
2500
-
2501
- *Dan McClain*
2502
-
2503
- * PostgreSQL array type support. Any datatype can be used to create an
2504
- array column, with full migration and schema dumper support.
2505
-
2506
- To declare an array column, use the following syntax:
671
+ *Kassio Borges*
2507
672
 
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
673
+ * Create a directory for sqlite3 file if not present on the system.
2516
674
 
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.
675
+ *Richard Schneeman*
2520
676
 
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).
677
+ * Removed redundant override of `xml` column definition for PG,
678
+ in order to use `xml` column type instead of `text`.
2525
679
 
2526
- If the `pg_array_parser` gem is available, it will be used when
2527
- parsing PostgreSQL's array representation.
680
+ *Paul Nikitochkin*, *Michael Nikitochkin*
2528
681
 
2529
- *Dan McClain*
682
+ * Revert `ActiveRecord::Relation#order` change that make new order
683
+ prepend the old one.
2530
684
 
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`.
685
+ Before:
2534
686
 
2535
- *Ernie Miller*
687
+ User.order("name asc").order("created_at desc")
688
+ # SELECT * FROM users ORDER BY created_at desc, name asc
2536
689
 
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.
690
+ After:
2539
691
 
2540
- *Konstantin Shabanov*
692
+ User.order("name asc").order("created_at desc")
693
+ # SELECT * FROM users ORDER BY name asc, created_at desc
2541
694
 
2542
- * Map interval with precision to string datatype in PostgreSQL. Fixes #7518.
695
+ This also affects order defined in `default_scope` or any kind of associations.
2543
696
 
2544
- *Yves Senn*
697
+ * Add ability to define how a class is converted to Arel predicates.
698
+ For example, adding a very vendor specific regex implementation:
2545
699
 
2546
- * Fix eagerly loading associations without primary keys. Fixes #4976.
700
+ regex_handler = proc do |column, value|
701
+ Arel::Nodes::InfixOperation.new('~', column, value.source)
702
+ end
703
+ ActiveRecord::PredicateBuilder.register_handler(Regexp, regex_handler)
2547
704
 
2548
- *Kelley Reynolds*
705
+ *Sean Griffin & @joannecheng*
2549
706
 
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.
707
+ * Don't allow `quote_value` to be called without a column.
2553
708
 
2554
- *Jan Bernacki*
709
+ Some adapters require column information to do their job properly.
710
+ By enforcing the provision of the column for this internal method
711
+ we ensure that those using adapters that require column information
712
+ will always get the proper behavior.
2555
713
 
2556
- * Fix bug when calling `store_accessor` multiple times.
2557
- Fixes #7532.
714
+ *Ben Woosley*
2558
715
 
2559
- *Matt Jones*
716
+ * When using optimistic locking, `update` was not passing the column to `quote_value`
717
+ to allow the connection adapter to properly determine how to quote the value. This was
718
+ affecting certain databases that use specific column types.
2560
719
 
2561
- * Fix store attributes that show the changes incorrectly.
2562
- Fixes #7532.
720
+ Fixes #6763.
2563
721
 
2564
- *Matt Jones*
722
+ *Alfred Wong*
2565
723
 
2566
- * Fix `ActiveRecord::Relation#pluck` when columns or tables are reserved words.
724
+ * rescue from all exceptions in `ConnectionManagement#call`
2567
725
 
2568
- *Ian Lesperance*
726
+ Fixes #11497.
2569
727
 
2570
- * Allow JSON columns to be created in PostgreSQL and properly encoded/decoded.
2571
- to/from database.
728
+ As `ActiveRecord::ConnectionAdapters::ConnectionManagement` middleware does
729
+ not rescue from Exception (but only from StandardError), the Connection
730
+ Pool quickly runs out of connections when multiple erroneous Requests come
731
+ in right after each other.
2572
732
 
2573
- *Dickson S. Guedes*
733
+ Rescuing from all exceptions and not just StandardError, fixes this
734
+ behaviour.
2574
735
 
2575
- * Fix time column type casting for invalid time string values to correctly return `nil`.
736
+ *Vipul A M*
2576
737
 
2577
- *Adam Meehan*
738
+ * `change_column` for PostgreSQL adapter respects the `:array` option.
2578
739
 
2579
- * Allow to pass Symbol or Proc into `:limit` option of #accepts_nested_attributes_for.
740
+ *Yves Senn*
2580
741
 
2581
- *Mikhail Dieterle*
742
+ * Remove deprecation warning from `attribute_missing` for attributes that are columns.
2582
743
 
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.
744
+ *Arun Agrawal*
2585
745
 
2586
- *Prem Sichanugrist*
746
+ * Remove extra decrement of transaction deep level.
2587
747
 
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.
748
+ Fixes #4566.
2591
749
 
2592
- *Dave Desrochers*
750
+ *Paul Nikitochkin*
2593
751
 
2594
- * `serialized_attributes` and `_attr_readonly` become class method only. Instance reader methods are deprecated.
752
+ * Reset @column_defaults when assigning `locking_column`.
753
+ We had a potential problem. For example:
2595
754
 
2596
- *kennyj*
755
+ class Post < ActiveRecord::Base
756
+ self.column_defaults # if we call this unintentionally before setting locking_column ...
757
+ self.locking_column = 'my_locking_column'
758
+ end
2597
759
 
2598
- * Round usec when comparing timestamp attributes in the dirty tracking.
2599
- Fixes #6975.
760
+ Post.column_defaults["my_locking_column"]
761
+ => nil # expected value is 0 !
2600
762
 
2601
763
  *kennyj*
2602
764
 
2603
- * Use inversed parent for first and last child of `has_many` association.
2604
-
2605
- *Ravil Bayramgalin*
765
+ * Remove extra select and update queries on save/touch/destroy ActiveRecord model
766
+ with belongs to reflection with option `touch: true`.
2606
767
 
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.
768
+ Fixes #11288.
2610
769
 
2611
- *Ari Pollak*
770
+ *Paul Nikitochkin*
2612
771
 
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.
772
+ * Remove deprecated nil-passing to the following `SchemaCache` methods:
773
+ `primary_keys`, `tables`, `columns` and `columns_hash`.
2615
774
 
2616
- *Christian Seiler*
775
+ *Yves Senn*
2617
776
 
2618
- * Raise `ArgumentError` if list of attributes to change is empty in `update_all`.
777
+ * Remove deprecated block filter from `ActiveRecord::Migrator#migrate`.
2619
778
 
2620
- *Roman Shatsov*
779
+ *Yves Senn*
2621
780
 
2622
- * Fix AR#create to return an unsaved record when AR::RecordInvalid is
2623
- raised. Fixes #3217.
781
+ * Remove deprecated String constructor from `ActiveRecord::Migrator`.
2624
782
 
2625
- *Dave Yeu*
783
+ *Yves Senn*
2626
784
 
2627
- * Fixed table name prefix that is generated in engines for namespaced models.
785
+ * Remove deprecated `scope` use without passing a callable object.
2628
786
 
2629
- *Wojciech Wnętrzak*
787
+ *Arun Agrawal*
2630
788
 
2631
- * Make sure `:environment` task is executed before `db:schema:load` or `db:structure:load`.
2632
- Fixes #4772.
789
+ * Remove deprecated `transaction_joinable=` in favor of `begin_transaction`
790
+ with `:joinable` option.
2633
791
 
2634
- *Seamus Abshere*
792
+ *Arun Agrawal*
2635
793
 
2636
- * Allow Relation#merge to take a proc.
794
+ * Remove deprecated `decrement_open_transactions`.
2637
795
 
2638
- This was requested by DHH to allow creating of one's own custom
2639
- association macros.
796
+ *Arun Agrawal*
2640
797
 
2641
- For example:
798
+ * Remove deprecated `increment_open_transactions`.
2642
799
 
2643
- module Commentable
2644
- def has_many_comments(extra)
2645
- has_many :comments, -> { where(:foo).merge(extra) }
2646
- end
2647
- end
800
+ *Arun Agrawal*
2648
801
 
2649
- class Post < ActiveRecord::Base
2650
- extend Commentable
2651
- has_many_comments -> { where(:bar) }
2652
- end
802
+ * Remove deprecated `PostgreSQLAdapter#outside_transaction?`
803
+ method. You can use `#transaction_open?` instead.
2653
804
 
2654
- *Jon Leighton*
805
+ *Yves Senn*
2655
806
 
2656
- * Add CollectionProxy#scope.
807
+ * Remove deprecated `ActiveRecord::Fixtures.find_table_name` in favor of
808
+ `ActiveRecord::Fixtures.default_fixture_model_name`.
2657
809
 
2658
- This can be used to get a Relation from an association.
810
+ *Vipul A M*
2659
811
 
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.
812
+ * Removed deprecated `columns_for_remove` from `SchemaStatements`.
2662
813
 
2663
- This was requested by DHH, to facilitate code like this:
814
+ *Neeraj Singh*
2664
815
 
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
816
+ * Remove deprecated `SchemaStatements#distinct`.
2671
817
 
2672
- *Jon Leighton*
818
+ *Francesco Rodriguez*
2673
819
 
2674
- * Add `Relation#load`.
820
+ * Move deprecated `ActiveRecord::TestCase` into the rails test
821
+ suite. The class is no longer public and is only used for internal
822
+ Rails tests.
2675
823
 
2676
- This method explicitly loads the records and then returns `self`.
824
+ *Yves Senn*
2677
825
 
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.
826
+ * Removed support for deprecated option `:restrict` for `:dependent`
827
+ in associations.
2682
828
 
2683
- Example:
829
+ *Neeraj Singh*
2684
830
 
2685
- @posts = Post.where(published: true).load
831
+ * Removed support for deprecated `delete_sql` in associations.
2686
832
 
2687
- *Jon Leighton*
833
+ *Neeraj Singh*
2688
834
 
2689
- * `Relation#order`: make new order prepend old one.
835
+ * Removed support for deprecated `insert_sql` in associations.
2690
836
 
2691
- User.order("name asc").order("created_at desc")
2692
- # SELECT * FROM users ORDER BY created_at desc, name asc
837
+ *Neeraj Singh*
2693
838
 
2694
- This also affects order defined in `default_scope` or any kind of associations.
839
+ * Removed support for deprecated `finder_sql` in associations.
2695
840
 
2696
- *Bogdan Gusiev*
841
+ *Neeraj Singh*
2697
842
 
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.
843
+ * Support array as root element in JSON fields.
2700
844
 
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.
845
+ *Alexey Noskov & Francesco Rodriguez*
2704
846
 
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.
847
+ * Removed support for deprecated `counter_sql` in associations.
2708
848
 
2709
- `Model.scoped` is deprecated in favour of `Model.all`.
849
+ *Neeraj Singh*
2710
850
 
2711
- `Relation#all` still returns an array, but is deprecated (since it
2712
- would serve no purpose if we made it return a `Relation`).
851
+ * Do not invoke callbacks when `delete_all` is called on collection.
2713
852
 
2714
- *Jon Leighton*
853
+ Method `delete_all` should not be invoking callbacks and this
854
+ feature was deprecated in Rails 4.0. This is being removed.
855
+ `delete_all` will continue to honor the `:dependent` option. However
856
+ if `:dependent` value is `:destroy` then the `:delete_all` deletion
857
+ strategy for that collection will be applied.
2715
858
 
2716
- * `:finder_sql` and `:counter_sql` options on collection associations
2717
- are deprecated. Please transition to using scopes.
859
+ User can also force a deletion strategy by passing parameter to
860
+ `delete_all`. For example you can do `@post.comments.delete_all(:nullify)`.
2718
861
 
2719
- *Jon Leighton*
862
+ *Neeraj Singh*
2720
863
 
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`.
864
+ * Calling default_scope without a proc will now raise `ArgumentError`.
2724
865
 
2725
- *Jon Leighton*
866
+ *Neeraj Singh*
2726
867
 
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.
868
+ * Removed deprecated method `type_cast_code` from Column.
2731
869
 
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"}
870
+ *Neeraj Singh*
2735
871
 
2736
- *Sebastian Martinez + Rafael Mendonça França*
872
+ * Removed deprecated options `delete_sql` and `insert_sql` from HABTM
873
+ association.
2737
874
 
2738
- * The migration generator now creates a join table with (commented) indexes every time
2739
- the migration name contains the word `join_table`:
875
+ Removed deprecated options `finder_sql` and `counter_sql` from
876
+ collection association.
2740
877
 
2741
- rails g migration create_join_table_for_artists_and_musics artist_id:index music_id
878
+ *Neeraj Singh*
2742
879
 
2743
- *Aleksey Magusev*
880
+ * Remove deprecated `ActiveRecord::Base#connection` method.
881
+ Make sure to access it via the class.
2744
882
 
2745
- * Add `add_reference` and `remove_reference` schema statements. Aliases, `add_belongs_to`
2746
- and `remove_belongs_to` are acceptable. References are reversible.
883
+ *Yves Senn*
2747
884
 
2748
- Examples:
885
+ * Remove deprecation warning for `auto_explain_threshold_in_seconds`.
2749
886
 
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)
887
+ *Yves Senn*
2756
888
 
2757
- *Aleksey Magusev*
889
+ * Remove deprecated `:distinct` option from `Relation#count`.
2758
890
 
2759
- * Add `:default` and `:null` options to `column_exists?`.
891
+ *Yves Senn*
2760
892
 
2761
- column_exists?(:testings, :taggable_id, :integer, null: false)
2762
- column_exists?(:testings, :taggable_type, :string, default: 'Photo')
893
+ * Removed deprecated methods `partial_updates`, `partial_updates?` and
894
+ `partial_updates=`.
2763
895
 
2764
- *Aleksey Magusev*
896
+ *Neeraj Singh*
2765
897
 
2766
- * `ActiveRecord::Relation#inspect` now makes it clear that you are
2767
- dealing with a `Relation` object rather than an array:.
898
+ * Removed deprecated method `scoped`.
2768
899
 
2769
- User.where(age: 30).inspect
2770
- # => <ActiveRecord::Relation [#<User ...>, #<User ...>, ...]>
900
+ *Neeraj Singh*
2771
901
 
2772
- User.where(age: 30).to_a.inspect
2773
- # => [#<User ...>, #<User ...>]
902
+ * Removed deprecated method `default_scopes?`.
2774
903
 
2775
- The number of records displayed will be limited to 10.
904
+ *Neeraj Singh*
2776
905
 
2777
- *Brian Cardarella, Jon Leighton & Damien Mathieu*
906
+ * Remove implicit join references that were deprecated in 4.0.
2778
907
 
2779
- * Add `collation` and `ctype` support to PostgreSQL. These are available for PostgreSQL 8.4 or later.
2780
908
  Example:
2781
909
 
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.
910
+ # before with implicit joins
911
+ Comment.where('posts.author_id' => 7)
2798
912
 
2799
- *Nick Monje & Brent Wheeldon*
913
+ # after
914
+ Comment.references(:posts).where('posts.author_id' => 7)
2800
915
 
2801
- * `FinderMethods#exists?` now returns `false` with the `false` argument.
2802
-
2803
- *Egor Lynko*
916
+ *Yves Senn*
2804
917
 
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:
918
+ * Apply default scope when joining associations. For example:
2808
919
 
2809
- def change
2810
- create_table :foobars do |t|
2811
- t.timestamps precision: 0
2812
- end
920
+ class Post < ActiveRecord::Base
921
+ default_scope -> { where published: true }
2813
922
  end
2814
923
 
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.
924
+ class Comment
925
+ belongs_to :post
926
+ end
2862
927
 
2863
- *Andrew White*
928
+ When calling `Comment.joins(:post)`, we expect to receive only
929
+ comments on published posts, since that is the default scope for
930
+ posts.
2864
931
 
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.
932
+ Before this change, the default scope from `Post` was not applied,
933
+ so we'd get comments on unpublished posts.
2868
934
 
2869
- class User < ActiveRecord::Base
2870
- store :settings, accessors: [:color, :homepage]
2871
- end
935
+ *Jon Leighton*
2872
936
 
2873
- User.stored_attributes[:settings] # [:color, :homepage]
937
+ * Remove `activerecord-deprecated_finders` as a dependency.
2874
938
 
2875
- *Joost Baaij & Carlos Antonio da Silva*
939
+ *Łukasz Strzałkowski*
2876
940
 
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.
941
+ * Remove Oracle / Sqlserver / Firebird database tasks that were deprecated in 4.0.
2880
942
 
2881
943
  *kennyj*
2882
944
 
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`.
945
+ * `find_each` now returns an `Enumerator` when called without a block, so that it
946
+ can be chained with other `Enumerable` methods.
2894
947
 
2895
- *Marc-André Lafortune*
948
+ *Ben Woosley*
2896
949
 
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.
950
+ * `ActiveRecord::Result.each` now returns an `Enumerator` when called without
951
+ a block, so that it can be chained with other `Enumerable` methods.
2900
952
 
2901
- class Person < ActiveRecord::Base
2902
- has_many :pets
2903
- end
953
+ *Ben Woosley*
2904
954
 
2905
- person.pets.delete("1") # => [#<Pet id: 1>]
2906
- person.pets.delete(2, 3) # => [#<Pet id: 2>, #<Pet id: 3>]
955
+ * Flatten merged join_values before building the joins.
2907
956
 
2908
- *Francesco Rodriguez*
957
+ While joining_values special treatment is given to string values.
958
+ By flattening the array it ensures that string values are detected
959
+ as strings and not arrays.
2909
960
 
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:
961
+ Fixes #10669.
2913
962
 
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!`
963
+ *Neeraj Singh and iwiznia*
2923
964
 
2924
- The implementation of the deprecated dynamic finders has been moved
2925
- to the `activerecord-deprecated_finders` gem. See below for details.
965
+ * Do not load all child records for inverse case.
2926
966
 
2927
- *Jon Leighton*
967
+ currently `post.comments.find(Comment.first.id)` would load all
968
+ comments for the given post to set the inverse association.
2928
969
 
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:
970
+ This has a huge performance penalty. Because if post has 100k
971
+ records and all these 100k records would be loaded in memory
972
+ even though the comment id was supplied.
2932
973
 
2933
- Post.find(:all, conditions: { comments_count: 10 }, limit: 5)
974
+ Fix is to use in-memory records only if loaded? is true. Otherwise
975
+ load the records using full sql.
2934
976
 
2935
- Should be rewritten in the new style which has existed since Rails 3:
977
+ Fixes #10509.
2936
978
 
2937
- Post.where(comments_count: 10).limit(5)
979
+ *Neeraj Singh*
2938
980
 
2939
- Note that as an interim step, it is possible to rewrite the above as:
981
+ * `inspect` on Active Record model classes does not initiate a
982
+ new connection. This means that calling `inspect`, when the
983
+ database is missing, will no longer raise an exception.
984
+ Fixes #10936.
2940
985
 
2941
- Post.all.merge(where: { comments_count: 10 }, limit: 5)
986
+ Example:
2942
987
 
2943
- This could save you a lot of work if there is a lot of old-style
2944
- finder usage in your application.
988
+ Author.inspect # => "Author(no database connection)"
2945
989
 
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:
990
+ *Yves Senn*
2950
991
 
2951
- * `:conditions` becomes `:where`.
2952
- * `:include` becomes `:includes`.
992
+ * Handle single quotes in PostgreSQL default column values.
993
+ Fixes #10881.
2953
994
 
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.
995
+ *Dylan Markow*
2959
996
 
2960
- *Jon Leighton*
997
+ * Log the sql that is actually sent to the database.
2961
998
 
2962
- * It's not possible anymore to destroy a model marked as read only.
999
+ If I have a query that produces sql
1000
+ `WHERE "users"."name" = 'a b'` then in the log all the
1001
+ whitespace is being squeezed. So the sql that is printed in the
1002
+ log is `WHERE "users"."name" = 'a b'`.
2963
1003
 
2964
- *Johannes Barre*
1004
+ Do not squeeze whitespace out of sql queries. Fixes #10982.
2965
1005
 
2966
- * Added ability to ActiveRecord::Relation#from to accept other ActiveRecord::Relation objects.
1006
+ *Neeraj Singh*
2967
1007
 
2968
- Record.from(subquery)
2969
- Record.from(subquery, :a)
1008
+ * Fixture setup no longer depends on `ActiveRecord::Base.configurations`.
1009
+ This is relevant when `ENV["DATABASE_URL"]` is used in place of a `database.yml`.
2970
1010
 
2971
- *Radoslav Stankov*
1011
+ *Yves Senn*
2972
1012
 
2973
- * Added custom coders support for ActiveRecord::Store. Now you can set
2974
- your custom coder like this:
1013
+ * Fix mysql2 adapter raises the correct exception when executing a query on a
1014
+ closed connection.
2975
1015
 
2976
- store :settings, accessors: [ :color, :homepage ], coder: JSON
1016
+ *Yves Senn*
2977
1017
 
2978
- *Andrey Voronkov*
1018
+ * Ambiguous reflections are on :through relationships are no longer supported.
1019
+ For example, you need to change this:
2979
1020
 
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`.
1021
+ class Author < ActiveRecord::Base
1022
+ has_many :posts
1023
+ has_many :taggings, through: :posts
1024
+ end
2983
1025
 
2984
- *Michael Pearson*
1026
+ class Post < ActiveRecord::Base
1027
+ has_one :tagging
1028
+ has_many :taggings
1029
+ end
2985
1030
 
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`.
1031
+ class Tagging < ActiveRecord::Base
1032
+ end
2989
1033
 
2990
- *Marcelo Silveira*
1034
+ To this:
2991
1035
 
2992
- * Added an `:index` option to automatically create indexes for references
2993
- and belongs_to statements in migrations.
1036
+ class Author < ActiveRecord::Base
1037
+ has_many :posts
1038
+ has_many :taggings, through: :posts, source: :tagging
1039
+ end
2994
1040
 
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:
1041
+ class Post < ActiveRecord::Base
1042
+ has_one :tagging
1043
+ has_many :taggings
1044
+ end
2998
1045
 
2999
- create_table :messages do |t|
3000
- t.references :person, index: true
3001
- end
1046
+ class Tagging < ActiveRecord::Base
1047
+ end
3002
1048
 
3003
- Is the same as:
1049
+ *Aaron Patterson*
3004
1050
 
3005
- create_table :messages do |t|
3006
- t.references :person
3007
- end
3008
- add_index :messages, :person_id
1051
+ * Remove column restrictions for `count`, let the database raise if the SQL is
1052
+ invalid. The previous behavior was untested and surprising for the user.
1053
+ Fixes #5554.
3009
1054
 
3010
- Generators have also been updated to use the new syntax.
1055
+ Example:
3011
1056
 
3012
- *Joshua Wood*
1057
+ User.select("name, username").count
1058
+ # Before => SELECT count(*) FROM users
1059
+ # After => ActiveRecord::StatementInvalid
3013
1060
 
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:
1061
+ # you can still use `count(:all)` to perform a query unrelated to the
1062
+ # selected columns
1063
+ User.select("name, username").count(:all) # => SELECT count(*) FROM users
3017
1064
 
3018
- Post.find_by name: 'Spartacus', rating: 4
3019
- Post.find_by "published_at < ?", 2.weeks.ago
3020
- Post.find_by! name: 'Spartacus'
1065
+ *Yves Senn*
3021
1066
 
3022
- *Jon Leighton*
1067
+ * Rails now automatically detects inverse associations. If you do not set the
1068
+ `:inverse_of` option on the association, then Active Record will guess the
1069
+ inverse association based on heuristics.
3023
1070
 
3024
- * Added ActiveRecord::Base#slice to return a hash of the given methods with
3025
- their names as keys and returned values as values.
1071
+ Note that automatic inverse detection only works on `has_many`, `has_one`,
1072
+ and `belongs_to` associations. Extra options on the associations will
1073
+ also prevent the association's inverse from being found automatically.
3026
1074
 
3027
- *Guillermo Iguaran*
1075
+ The automatic guessing of the inverse association uses a heuristic based
1076
+ on the name of the class, so it may not work for all associations,
1077
+ especially the ones with non-standard names.
3028
1078
 
3029
- * Deprecate eager-evaluated scopes.
1079
+ You can turn off the automatic detection of inverse associations by setting
1080
+ the `:inverse_of` option to `false` like so:
3030
1081
 
3031
- Don't use this:
1082
+ class Taggable < ActiveRecord::Base
1083
+ belongs_to :tag, inverse_of: false
1084
+ end
3032
1085
 
3033
- scope :red, where(color: 'red')
3034
- default_scope where(color: 'red')
1086
+ *John Wang*
3035
1087
 
3036
- Use this:
1088
+ * Fix `add_column` with `array` option when using PostgreSQL. Fixes #10432
3037
1089
 
3038
- scope :red, -> { where(color: 'red') }
3039
- default_scope { where(color: 'red') }
1090
+ *Adam Anderson*
3040
1091
 
3041
- The former has numerous issues. It is a common newbie gotcha to do
3042
- the following:
1092
+ * Usage of `implicit_readonly` is being removed`. Please use `readonly` method
1093
+ explicitly to mark records as `readonly.
1094
+ Fixes #10615.
3043
1095
 
3044
- scope :recent, where(published_at: Time.now - 2.weeks)
1096
+ Example:
3045
1097
 
3046
- Or a more subtle variant:
1098
+ user = User.joins(:todos).select("users.*, todos.title as todos_title").readonly(true).first
1099
+ user.todos_title = 'clean pet'
1100
+ user.save! # will raise error
3047
1101
 
3048
- scope :recent, -> { where(published_at: Time.now - 2.weeks) }
3049
- scope :recent_red, recent.where(color: 'red')
1102
+ *Yves Senn*
3050
1103
 
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:
1104
+ * Fix the `:primary_key` option for `has_many` associations.
1105
+ Fixes #10693.
3054
1106
 
3055
- scope :remove_conditions, except(:where)
3056
- where(...).remove_conditions # => still has conditions
1107
+ *Yves Senn*
3057
1108
 
3058
- *Jon Leighton*
1109
+ * Fix bug where tiny types are incorrectly coerced as boolean when the length is more than 1.
3059
1110
 
3060
- * Remove IdentityMap
1111
+ Fixes #10620.
3061
1112
 
3062
- IdentityMap has never graduated to be an "enabled-by-default" feature, due
3063
- to some inconsistencies with associations, as described in this commit:
1113
+ *Aaron Patterson*
3064
1114
 
3065
- https://github.com/rails/rails/commit/302c912bf6bcd0fa200d964ec2dc4a44abe328a6
1115
+ * Also support extensions in PostgreSQL 9.1. This feature has been supported since 9.1.
3066
1116
 
3067
- Hence the removal from the codebase, until such issues are fixed.
1117
+ *kennyj*
3068
1118
 
3069
- *Carlos Antonio da Silva*
1119
+ * Deprecate `ConnectionAdapters::SchemaStatements#distinct`,
1120
+ as it is no longer used by internals.
3070
1121
 
3071
- * Added the schema cache dump feature.
1122
+ *Ben Woosley*
3072
1123
 
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.
1124
+ * Fix pending migrations error when loading schema and `ActiveRecord::Base.table_name_prefix`
1125
+ is not blank.
3075
1126
 
3076
- Usage notes:
1127
+ Call `assume_migrated_upto_version` on connection to prevent it from first
1128
+ being picked up in `method_missing`.
3077
1129
 
3078
- 1) execute rake task.
3079
- RAILS_ENV=production bundle exec rake db:schema:cache:dump
3080
- => generate db/schema_cache.dump
1130
+ In the base class, `Migration`, `method_missing` expects the argument to be a
1131
+ table name, and calls `proper_table_name` on the arguments before sending to
1132
+ `connection`. If `table_name_prefix` or `table_name_suffix` is used, the schema
1133
+ version changes to `prefix_version_suffix`, breaking `rake test:prepare`.
3081
1134
 
3082
- 2) add config.active_record.use_schema_cache_dump = true in config/production.rb. BTW, true is default.
1135
+ Fixes #10411.
3083
1136
 
3084
- 3) boot rails.
3085
- RAILS_ENV=production bundle exec rails server
3086
- => use db/schema_cache.dump
1137
+ *Kyle Stevens*
3087
1138
 
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
1139
+ * Method `read_attribute_before_type_cast` should accept input as symbol.
3091
1140
 
3092
- *kennyj*
1141
+ *Neeraj Singh*
3093
1142
 
3094
- * Added support for partial indices to PostgreSQL adapter.
1143
+ * Confirm a record has not already been destroyed before decrementing counter cache.
3095
1144
 
3096
- The `add_index` method now supports a `where` option that receives a
3097
- string with the partial index criteria.
1145
+ *Ben Tucker*
3098
1146
 
3099
- add_index(:accounts, :code, where: 'active')
1147
+ * Fixed a bug in `ActiveRecord#sanitize_sql_hash_for_conditions` in which
1148
+ `self.class` is an argument to `PredicateBuilder#build_from_hash`
1149
+ causing `PredicateBuilder` to call non-existent method
1150
+ `Class#reflect_on_association`.
3100
1151
 
3101
- generates
1152
+ *Zach Ohlgren*
3102
1153
 
3103
- CREATE INDEX index_accounts_on_code ON accounts(code) WHERE active
1154
+ * While removing index if column option is missing then raise IrreversibleMigration exception.
3104
1155
 
3105
- *Marcelo Silveira*
1156
+ Following code should raise `IrreversibleMigration`. But the code was
1157
+ failing since options is an array and not a hash.
3106
1158
 
3107
- * Implemented `ActiveRecord::Relation#none` method.
1159
+ def change
1160
+ change_table :users do |t|
1161
+ t.remove_index [:name, :email]
1162
+ end
1163
+ end
3108
1164
 
3109
- The `none` method returns a chainable relation with zero records
3110
- (an instance of the NullRelation class).
1165
+ Fix was to check if the options is a Hash before operating on it.
3111
1166
 
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.
1167
+ Fixes #10419.
3114
1168
 
3115
- *Juanjo Bazán*
1169
+ *Neeraj Singh*
3116
1170
 
3117
- * Added the `ActiveRecord::NullRelation` class implementing the null
3118
- object pattern for the Relation class.
1171
+ * Do not overwrite manually built records during one-to-one nested attribute assignment
3119
1172
 
3120
- *Juanjo Bazán*
1173
+ For one-to-one nested associations, if you build the new (in-memory)
1174
+ child object yourself before assignment, then the NestedAttributes
1175
+ module will not overwrite it, e.g.:
3121
1176
 
3122
- * Added new `dependent: :restrict_with_error` option. This will add
3123
- an error to the model, rather than raising an exception.
1177
+ class Member < ActiveRecord::Base
1178
+ has_one :avatar
1179
+ accepts_nested_attributes_for :avatar
3124
1180
 
3125
- The `:restrict` option is renamed to `:restrict_with_exception` to
3126
- make this distinction explicit.
1181
+ def avatar
1182
+ super || build_avatar(width: 200)
1183
+ end
1184
+ end
3127
1185
 
3128
- *Manoj Kumar & Jon Leighton*
1186
+ member = Member.new
1187
+ member.avatar_attributes = {icon: 'sad'}
1188
+ member.avatar.width # => 200
3129
1189
 
3130
- * Added `create_join_table` migration helper to create HABTM join tables.
1190
+ *Olek Janiszewski*
3131
1191
 
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
1192
+ * fixes bug introduced by #3329. Now, when autosaving associations,
1193
+ deletions happen before inserts and saves. This prevents a 'duplicate
1194
+ unique value' database error that would occur if a record being created had
1195
+ the same value on a unique indexed field as that of a record being destroyed.
3138
1196
 
3139
- *Rafael Mendonça França*
1197
+ *Johnny Holton*
3140
1198
 
3141
- * The primary key is always initialized in the @attributes hash to `nil` (unless
3142
- another value has been specified).
1199
+ * Handle aliased attributes in ActiveRecord::Relation.
3143
1200
 
3144
- *Aaron Patterson*
1201
+ When using symbol keys, ActiveRecord will now translate aliased attribute names to the actual column name used in the database:
3145
1202
 
3146
- * In previous releases, the following would generate a single query with
3147
- an `OUTER JOIN comments`, rather than two separate queries:
1203
+ With the model
3148
1204
 
3149
- Post.includes(:comments)
3150
- .where("comments.name = 'foo'")
1205
+ class Topic
1206
+ alias_attribute :heading, :title
1207
+ end
3151
1208
 
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.
1209
+ The call
3155
1210
 
3156
- Therefore, it is now deprecated.
1211
+ Topic.where(heading: 'The First Topic')
3157
1212
 
3158
- To avoid deprecation warnings and for future compatibility, you must
3159
- explicitly state which tables you reference, when using SQL snippets:
1213
+ should yield the same result as
3160
1214
 
3161
- Post.includes(:comments)
3162
- .where("comments.name = 'foo'")
3163
- .references(:comments)
1215
+ Topic.where(title: 'The First Topic')
3164
1216
 
3165
- Note that you do not need to explicitly specify references in the
3166
- following cases, as they can be automatically inferred:
1217
+ This also applies to ActiveRecord::Relation::Calculations calls such as `Model.sum(:aliased)` and `Model.pluck(:aliased)`.
3167
1218
 
3168
- Post.includes(:comments).where(comments: { name: 'foo' })
3169
- Post.includes(:comments).where('comments.name' => 'foo')
3170
- Post.includes(:comments).order('comments.name')
1219
+ This will not work with SQL fragment strings like `Model.sum('DISTINCT aliased')`.
3171
1220
 
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.
1221
+ *Godfrey Chan*
3175
1222
 
3176
- *Jon Leighton*
1223
+ * Mute `psql` output when running rake db:schema:load.
3177
1224
 
3178
- * Support for the `schema_info` table has been dropped. Please
3179
- switch to `schema_migrations`.
1225
+ *Godfrey Chan*
3180
1226
 
3181
- *Aaron Patterson*
1227
+ * Trigger a save on `has_one association=(associate)` when the associate contents have changed.
3182
1228
 
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.
1229
+ Fix #8856.
3185
1230
 
3186
- *Aaron Patterson*
1231
+ *Chris Thompson*
3187
1232
 
3188
- * PostgreSQL hstore records can be created.
1233
+ * Abort a rake task when missing db/structure.sql like `db:schema:load` task.
3189
1234
 
3190
- *Aaron Patterson*
1235
+ *kennyj*
3191
1236
 
3192
- * PostgreSQL hstore types are automatically deserialized from the database.
1237
+ * rake:db:test:prepare falls back to original environment after execution.
3193
1238
 
3194
- *Aaron Patterson*
1239
+ *Slava Markevich*
3195
1240
 
3196
- Please check [3-2-stable](https://github.com/rails/rails/blob/3-2-stable/activerecord/CHANGELOG.md) for previous changes.
1241
+ Please check [4-0-stable](https://github.com/rails/rails/blob/4-0-stable/activerecord/CHANGELOG.md) for previous changes.