activerecord 1.0.0 → 4.0.0

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 (255) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +2102 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +213 -0
  5. data/examples/performance.rb +172 -0
  6. data/examples/simple.rb +14 -0
  7. data/lib/active_record/aggregations.rb +180 -84
  8. data/lib/active_record/associations/alias_tracker.rb +76 -0
  9. data/lib/active_record/associations/association.rb +248 -0
  10. data/lib/active_record/associations/association_scope.rb +135 -0
  11. data/lib/active_record/associations/belongs_to_association.rb +92 -0
  12. data/lib/active_record/associations/belongs_to_polymorphic_association.rb +35 -0
  13. data/lib/active_record/associations/builder/association.rb +108 -0
  14. data/lib/active_record/associations/builder/belongs_to.rb +98 -0
  15. data/lib/active_record/associations/builder/collection_association.rb +89 -0
  16. data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +39 -0
  17. data/lib/active_record/associations/builder/has_many.rb +15 -0
  18. data/lib/active_record/associations/builder/has_one.rb +25 -0
  19. data/lib/active_record/associations/builder/singular_association.rb +32 -0
  20. data/lib/active_record/associations/collection_association.rb +608 -0
  21. data/lib/active_record/associations/collection_proxy.rb +986 -0
  22. data/lib/active_record/associations/has_and_belongs_to_many_association.rb +58 -39
  23. data/lib/active_record/associations/has_many_association.rb +116 -85
  24. data/lib/active_record/associations/has_many_through_association.rb +197 -0
  25. data/lib/active_record/associations/has_one_association.rb +102 -0
  26. data/lib/active_record/associations/has_one_through_association.rb +36 -0
  27. data/lib/active_record/associations/join_dependency/join_association.rb +174 -0
  28. data/lib/active_record/associations/join_dependency/join_base.rb +24 -0
  29. data/lib/active_record/associations/join_dependency/join_part.rb +78 -0
  30. data/lib/active_record/associations/join_dependency.rb +235 -0
  31. data/lib/active_record/associations/join_helper.rb +45 -0
  32. data/lib/active_record/associations/preloader/association.rb +121 -0
  33. data/lib/active_record/associations/preloader/belongs_to.rb +17 -0
  34. data/lib/active_record/associations/preloader/collection_association.rb +24 -0
  35. data/lib/active_record/associations/preloader/has_and_belongs_to_many.rb +60 -0
  36. data/lib/active_record/associations/preloader/has_many.rb +17 -0
  37. data/lib/active_record/associations/preloader/has_many_through.rb +19 -0
  38. data/lib/active_record/associations/preloader/has_one.rb +23 -0
  39. data/lib/active_record/associations/preloader/has_one_through.rb +9 -0
  40. data/lib/active_record/associations/preloader/singular_association.rb +21 -0
  41. data/lib/active_record/associations/preloader/through_association.rb +63 -0
  42. data/lib/active_record/associations/preloader.rb +178 -0
  43. data/lib/active_record/associations/singular_association.rb +64 -0
  44. data/lib/active_record/associations/through_association.rb +87 -0
  45. data/lib/active_record/associations.rb +1437 -431
  46. data/lib/active_record/attribute_assignment.rb +201 -0
  47. data/lib/active_record/attribute_methods/before_type_cast.rb +70 -0
  48. data/lib/active_record/attribute_methods/dirty.rb +118 -0
  49. data/lib/active_record/attribute_methods/primary_key.rb +122 -0
  50. data/lib/active_record/attribute_methods/query.rb +40 -0
  51. data/lib/active_record/attribute_methods/read.rb +107 -0
  52. data/lib/active_record/attribute_methods/serialization.rb +162 -0
  53. data/lib/active_record/attribute_methods/time_zone_conversion.rb +59 -0
  54. data/lib/active_record/attribute_methods/write.rb +63 -0
  55. data/lib/active_record/attribute_methods.rb +393 -0
  56. data/lib/active_record/autosave_association.rb +426 -0
  57. data/lib/active_record/base.rb +268 -930
  58. data/lib/active_record/callbacks.rb +203 -230
  59. data/lib/active_record/coders/yaml_column.rb +38 -0
  60. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +638 -0
  61. data/lib/active_record/connection_adapters/abstract/database_limits.rb +67 -0
  62. data/lib/active_record/connection_adapters/abstract/database_statements.rb +390 -0
  63. data/lib/active_record/connection_adapters/abstract/query_cache.rb +95 -0
  64. data/lib/active_record/connection_adapters/abstract/quoting.rb +129 -0
  65. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +501 -0
  66. data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +70 -0
  67. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +873 -0
  68. data/lib/active_record/connection_adapters/abstract/transaction.rb +203 -0
  69. data/lib/active_record/connection_adapters/abstract_adapter.rb +389 -275
  70. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +782 -0
  71. data/lib/active_record/connection_adapters/column.rb +318 -0
  72. data/lib/active_record/connection_adapters/connection_specification.rb +96 -0
  73. data/lib/active_record/connection_adapters/mysql2_adapter.rb +273 -0
  74. data/lib/active_record/connection_adapters/mysql_adapter.rb +517 -90
  75. data/lib/active_record/connection_adapters/postgresql/array_parser.rb +97 -0
  76. data/lib/active_record/connection_adapters/postgresql/cast.rb +152 -0
  77. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +242 -0
  78. data/lib/active_record/connection_adapters/postgresql/oid.rb +366 -0
  79. data/lib/active_record/connection_adapters/postgresql/quoting.rb +171 -0
  80. data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +30 -0
  81. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +489 -0
  82. data/lib/active_record/connection_adapters/postgresql_adapter.rb +911 -138
  83. data/lib/active_record/connection_adapters/schema_cache.rb +129 -0
  84. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +624 -0
  85. data/lib/active_record/connection_adapters/statement_pool.rb +40 -0
  86. data/lib/active_record/connection_handling.rb +98 -0
  87. data/lib/active_record/core.rb +463 -0
  88. data/lib/active_record/counter_cache.rb +122 -0
  89. data/lib/active_record/dynamic_matchers.rb +131 -0
  90. data/lib/active_record/errors.rb +213 -0
  91. data/lib/active_record/explain.rb +38 -0
  92. data/lib/active_record/explain_registry.rb +30 -0
  93. data/lib/active_record/explain_subscriber.rb +29 -0
  94. data/lib/active_record/fixture_set/file.rb +55 -0
  95. data/lib/active_record/fixtures.rb +892 -138
  96. data/lib/active_record/inheritance.rb +200 -0
  97. data/lib/active_record/integration.rb +60 -0
  98. data/lib/active_record/locale/en.yml +47 -0
  99. data/lib/active_record/locking/optimistic.rb +181 -0
  100. data/lib/active_record/locking/pessimistic.rb +77 -0
  101. data/lib/active_record/log_subscriber.rb +82 -0
  102. data/lib/active_record/migration/command_recorder.rb +164 -0
  103. data/lib/active_record/migration/join_table.rb +15 -0
  104. data/lib/active_record/migration.rb +1015 -0
  105. data/lib/active_record/model_schema.rb +345 -0
  106. data/lib/active_record/nested_attributes.rb +546 -0
  107. data/lib/active_record/null_relation.rb +65 -0
  108. data/lib/active_record/persistence.rb +509 -0
  109. data/lib/active_record/query_cache.rb +56 -0
  110. data/lib/active_record/querying.rb +62 -0
  111. data/lib/active_record/railtie.rb +205 -0
  112. data/lib/active_record/railties/console_sandbox.rb +5 -0
  113. data/lib/active_record/railties/controller_runtime.rb +50 -0
  114. data/lib/active_record/railties/databases.rake +402 -0
  115. data/lib/active_record/railties/jdbcmysql_error.rb +16 -0
  116. data/lib/active_record/readonly_attributes.rb +30 -0
  117. data/lib/active_record/reflection.rb +544 -87
  118. data/lib/active_record/relation/batches.rb +93 -0
  119. data/lib/active_record/relation/calculations.rb +399 -0
  120. data/lib/active_record/relation/delegation.rb +125 -0
  121. data/lib/active_record/relation/finder_methods.rb +349 -0
  122. data/lib/active_record/relation/merger.rb +161 -0
  123. data/lib/active_record/relation/predicate_builder.rb +106 -0
  124. data/lib/active_record/relation/query_methods.rb +1044 -0
  125. data/lib/active_record/relation/spawn_methods.rb +73 -0
  126. data/lib/active_record/relation.rb +655 -0
  127. data/lib/active_record/result.rb +67 -0
  128. data/lib/active_record/runtime_registry.rb +17 -0
  129. data/lib/active_record/sanitization.rb +168 -0
  130. data/lib/active_record/schema.rb +65 -0
  131. data/lib/active_record/schema_dumper.rb +204 -0
  132. data/lib/active_record/schema_migration.rb +39 -0
  133. data/lib/active_record/scoping/default.rb +146 -0
  134. data/lib/active_record/scoping/named.rb +175 -0
  135. data/lib/active_record/scoping.rb +82 -0
  136. data/lib/active_record/serialization.rb +22 -0
  137. data/lib/active_record/serializers/xml_serializer.rb +197 -0
  138. data/lib/active_record/statement_cache.rb +26 -0
  139. data/lib/active_record/store.rb +156 -0
  140. data/lib/active_record/tasks/database_tasks.rb +203 -0
  141. data/lib/active_record/tasks/firebird_database_tasks.rb +56 -0
  142. data/lib/active_record/tasks/mysql_database_tasks.rb +143 -0
  143. data/lib/active_record/tasks/oracle_database_tasks.rb +45 -0
  144. data/lib/active_record/tasks/postgresql_database_tasks.rb +90 -0
  145. data/lib/active_record/tasks/sqlite_database_tasks.rb +51 -0
  146. data/lib/active_record/tasks/sqlserver_database_tasks.rb +48 -0
  147. data/lib/active_record/test_case.rb +96 -0
  148. data/lib/active_record/timestamp.rb +119 -0
  149. data/lib/active_record/transactions.rb +366 -69
  150. data/lib/active_record/translation.rb +22 -0
  151. data/lib/active_record/validations/associated.rb +49 -0
  152. data/lib/active_record/validations/presence.rb +65 -0
  153. data/lib/active_record/validations/uniqueness.rb +225 -0
  154. data/lib/active_record/validations.rb +64 -185
  155. data/lib/active_record/version.rb +11 -0
  156. data/lib/active_record.rb +149 -24
  157. data/lib/rails/generators/active_record/migration/migration_generator.rb +62 -0
  158. data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb +19 -0
  159. data/lib/rails/generators/active_record/migration/templates/migration.rb +39 -0
  160. data/lib/rails/generators/active_record/model/model_generator.rb +48 -0
  161. data/lib/rails/generators/active_record/model/templates/model.rb +10 -0
  162. data/lib/rails/generators/active_record/model/templates/module.rb +7 -0
  163. data/lib/rails/generators/active_record.rb +23 -0
  164. metadata +261 -161
  165. data/CHANGELOG +0 -581
  166. data/README +0 -361
  167. data/RUNNING_UNIT_TESTS +0 -36
  168. data/dev-utils/eval_debugger.rb +0 -9
  169. data/examples/associations.png +0 -0
  170. data/examples/associations.rb +0 -87
  171. data/examples/shared_setup.rb +0 -15
  172. data/examples/validation.rb +0 -88
  173. data/install.rb +0 -60
  174. data/lib/active_record/associations/association_collection.rb +0 -70
  175. data/lib/active_record/connection_adapters/sqlite_adapter.rb +0 -107
  176. data/lib/active_record/deprecated_associations.rb +0 -70
  177. data/lib/active_record/observer.rb +0 -71
  178. data/lib/active_record/support/class_attribute_accessors.rb +0 -43
  179. data/lib/active_record/support/class_inheritable_attributes.rb +0 -37
  180. data/lib/active_record/support/clean_logger.rb +0 -10
  181. data/lib/active_record/support/inflector.rb +0 -70
  182. data/lib/active_record/vendor/mysql.rb +0 -1117
  183. data/lib/active_record/vendor/simple.rb +0 -702
  184. data/lib/active_record/wrappers/yaml_wrapper.rb +0 -15
  185. data/lib/active_record/wrappings.rb +0 -59
  186. data/rakefile +0 -122
  187. data/test/abstract_unit.rb +0 -16
  188. data/test/aggregations_test.rb +0 -34
  189. data/test/all.sh +0 -8
  190. data/test/associations_test.rb +0 -477
  191. data/test/base_test.rb +0 -513
  192. data/test/class_inheritable_attributes_test.rb +0 -33
  193. data/test/connections/native_mysql/connection.rb +0 -24
  194. data/test/connections/native_postgresql/connection.rb +0 -24
  195. data/test/connections/native_sqlite/connection.rb +0 -24
  196. data/test/deprecated_associations_test.rb +0 -336
  197. data/test/finder_test.rb +0 -67
  198. data/test/fixtures/accounts/signals37 +0 -3
  199. data/test/fixtures/accounts/unknown +0 -2
  200. data/test/fixtures/auto_id.rb +0 -4
  201. data/test/fixtures/column_name.rb +0 -3
  202. data/test/fixtures/companies/first_client +0 -6
  203. data/test/fixtures/companies/first_firm +0 -4
  204. data/test/fixtures/companies/second_client +0 -6
  205. data/test/fixtures/company.rb +0 -37
  206. data/test/fixtures/company_in_module.rb +0 -33
  207. data/test/fixtures/course.rb +0 -3
  208. data/test/fixtures/courses/java +0 -2
  209. data/test/fixtures/courses/ruby +0 -2
  210. data/test/fixtures/customer.rb +0 -30
  211. data/test/fixtures/customers/david +0 -6
  212. data/test/fixtures/db_definitions/mysql.sql +0 -96
  213. data/test/fixtures/db_definitions/mysql2.sql +0 -4
  214. data/test/fixtures/db_definitions/postgresql.sql +0 -113
  215. data/test/fixtures/db_definitions/postgresql2.sql +0 -4
  216. data/test/fixtures/db_definitions/sqlite.sql +0 -85
  217. data/test/fixtures/db_definitions/sqlite2.sql +0 -4
  218. data/test/fixtures/default.rb +0 -2
  219. data/test/fixtures/developer.rb +0 -8
  220. data/test/fixtures/developers/david +0 -2
  221. data/test/fixtures/developers/jamis +0 -2
  222. data/test/fixtures/developers_projects/david_action_controller +0 -2
  223. data/test/fixtures/developers_projects/david_active_record +0 -2
  224. data/test/fixtures/developers_projects/jamis_active_record +0 -2
  225. data/test/fixtures/entrant.rb +0 -3
  226. data/test/fixtures/entrants/first +0 -3
  227. data/test/fixtures/entrants/second +0 -3
  228. data/test/fixtures/entrants/third +0 -3
  229. data/test/fixtures/fixture_database.sqlite +0 -0
  230. data/test/fixtures/fixture_database_2.sqlite +0 -0
  231. data/test/fixtures/movie.rb +0 -5
  232. data/test/fixtures/movies/first +0 -2
  233. data/test/fixtures/movies/second +0 -2
  234. data/test/fixtures/project.rb +0 -3
  235. data/test/fixtures/projects/action_controller +0 -2
  236. data/test/fixtures/projects/active_record +0 -2
  237. data/test/fixtures/reply.rb +0 -21
  238. data/test/fixtures/subscriber.rb +0 -5
  239. data/test/fixtures/subscribers/first +0 -2
  240. data/test/fixtures/subscribers/second +0 -2
  241. data/test/fixtures/topic.rb +0 -20
  242. data/test/fixtures/topics/first +0 -9
  243. data/test/fixtures/topics/second +0 -8
  244. data/test/fixtures_test.rb +0 -20
  245. data/test/inflector_test.rb +0 -104
  246. data/test/inheritance_test.rb +0 -125
  247. data/test/lifecycle_test.rb +0 -110
  248. data/test/modules_test.rb +0 -21
  249. data/test/multiple_db_test.rb +0 -46
  250. data/test/pk_test.rb +0 -57
  251. data/test/reflection_test.rb +0 -78
  252. data/test/thread_safety_test.rb +0 -33
  253. data/test/transactions_test.rb +0 -83
  254. data/test/unconnected_test.rb +0 -24
  255. data/test/validations_test.rb +0 -126
data/CHANGELOG.md ADDED
@@ -0,0 +1,2102 @@
1
+ ## Rails 4.0.0 (June 25, 2013) ##
2
+
3
+ * Fix `add_column` with `array` option when using PostgreSQL. Fixes #10432
4
+
5
+ * Do not overwrite manually built records during one-to-one nested attribute assignment
6
+
7
+ For one-to-one nested associations, if you build the new (in-memory)
8
+ child object yourself before assignment, then the NestedAttributes
9
+ module will not overwrite it, e.g.:
10
+
11
+ class Member < ActiveRecord::Base
12
+ has_one :avatar
13
+ accepts_nested_attributes_for :avatar
14
+
15
+ def avatar
16
+ super || build_avatar(width: 200)
17
+ end
18
+ end
19
+
20
+ member = Member.new
21
+ member.avatar_attributes = {icon: 'sad'}
22
+ member.avatar.width # => 200
23
+
24
+ *Olek Janiszewski*
25
+
26
+ * fixes bug introduced by #3329. Now, when autosaving associations,
27
+ deletions happen before inserts and saves. This prevents a 'duplicate
28
+ unique value' database error that would occur if a record being created had
29
+ the same value on a unique indexed field as that of a record being destroyed.
30
+
31
+ *Adam Anderson*
32
+
33
+
34
+ * Fix pending migrations error when loading schema and `ActiveRecord::Base.table_name_prefix`
35
+ is not blank.
36
+
37
+ Call `assume_migrated_upto_version` on connection to prevent it from first
38
+ being picked up in `method_missing`.
39
+
40
+ In the base class, `Migration`, `method_missing` expects the argument to be a
41
+ table name, and calls `proper_table_name` on the arguments before sending to
42
+ `connection`. If `table_name_prefix` or `table_name_suffix` is used, the schema
43
+ version changes to `prefix_version_suffix`, breaking `rake test:prepare`.
44
+
45
+ Fixes #10411.
46
+
47
+ *Kyle Stevens*
48
+
49
+ * Mute `psql` output when running rake db:schema:load.
50
+
51
+ *Godfrey Chan*
52
+
53
+ * Trigger a save on `has_one association=(associate)` when the associate contents have changed.
54
+
55
+ Fix #8856.
56
+
57
+ *Chris Thompson*
58
+
59
+ * Allow to use databases.rake tasks without having `Rails.application`.
60
+
61
+ *Piotr Sarnacki*
62
+
63
+ * Fix a `SystemStackError` problem when using time zone aware or serialized attributes.
64
+ In current implementation, we reuse `column_types` argument when initiating an instance.
65
+ If an instance has serialized or time zone aware attributes, `column_types` is
66
+ wrapped multiple times in `decorate_columns` method. Thus the above error occurs.
67
+
68
+ *Dan Erikson & kennyj*
69
+
70
+ * Fix for a regression bug in which counter cache columns were not being updated
71
+ when record was pushed into a has_many association. For example:
72
+
73
+ Post.first.comments << Comment.create
74
+
75
+ Fixes #3891.
76
+
77
+ *Matthew Robertson*
78
+
79
+ * If a model was instantiated from the database using `select`, `respond_to?`
80
+ returns false for non-selected attributes. For example:
81
+
82
+ post = Post.select(:title).first
83
+ post.respond_to?(:body) # => false
84
+
85
+ post = Post.select('title as post_title').first
86
+ post.respond_to?(:title) # => false
87
+
88
+ Fixes #4208.
89
+
90
+ *Neeraj Singh*
91
+
92
+ * Run `rake migrate:down` & `rake migrate:up` in transaction if database supports.
93
+
94
+ *Alexander Bondarev*
95
+
96
+ * `0x` prefix must be added when assigning hexadecimal string into `bit` column in PostgreSQL.
97
+
98
+ *kennyj*
99
+
100
+ * Added Statement Cache to allow the caching of a single statement. The cache works by
101
+ duping the relation returned from yielding a statement, which allows skipping the AST
102
+ building phase for following executes. The cache returns results in array format.
103
+
104
+ Example:
105
+
106
+ cache = ActiveRecord::StatementCache.new do
107
+ Book.where(name: "my book").limit(100)
108
+ end
109
+
110
+ books = cache.execute
111
+
112
+ The solution attempts to get closer to the speed of `find_by_sql` but still maintaining
113
+ the expressiveness of the Active Record queries.
114
+
115
+ *Olli Rissanen*
116
+
117
+ * Preserve context while merging relations with join information.
118
+
119
+ class Comment < ActiveRecord::Base
120
+ belongs_to :post
121
+ end
122
+
123
+ class Author < ActiveRecord::Base
124
+ has_many :posts
125
+ end
126
+
127
+ class Post < ActiveRecord::Base
128
+ belongs_to :author
129
+ has_many :comments
130
+ end
131
+
132
+ `Comment.joins(:post).merge(Post.joins(:author).merge(Author.where(:name => "Joe Blogs"))).all`
133
+ would fail with
134
+ `ActiveRecord::ConfigurationError: Association named 'author' was not found on Comment`.
135
+
136
+ It is failing because `all` is being called on relation which looks like this after all
137
+ the merging: `{:joins=>[:post, :author], :where=>[#<Arel::Nodes::Equality: ....}`. In this
138
+ relation all the context that `Post` was joined with `Author` is lost and hence the error
139
+ that `author` was not found on `Comment`.
140
+
141
+ The solution is to build `JoinAssociation` when two relations with join information are being
142
+ merged. And later while building the Arel use the previously built `JoinAssociation` record
143
+ in `JoinDependency#graft` to build the right from clause.
144
+ Fixes #3002.
145
+
146
+ *Jared Armstrong and Neeraj Singh*
147
+
148
+ * `default_scopes?` is deprecated. Check for `default_scopes.empty?` instead.
149
+
150
+ *Agis Anastasopoulos*
151
+
152
+ * Default values for PostgreSQL bigint types now get parsed and dumped to the
153
+ schema correctly.
154
+
155
+ *Erik Peterson*
156
+
157
+ * Fix associations with `:inverse_of` option when building association
158
+ with a block. Inside the block the parent object was different then
159
+ after the block.
160
+
161
+ Example:
162
+
163
+ parent.association.build do |child|
164
+ child.parent.equal?(parent) # false
165
+ end
166
+
167
+ # vs
168
+
169
+ child = parent.association.build
170
+ child.parent.equal?(parent) # true
171
+
172
+ *Michal Cichra*
173
+
174
+ * `has_many` using `:through` now obeys the order clause mentioned in
175
+ through association.
176
+ Fixes #10016.
177
+
178
+ *Neeraj Singh*
179
+
180
+ * `belongs_to :touch` behavior now touches old association when
181
+ transitioning to new association.
182
+
183
+ class Passenger < ActiveRecord::Base
184
+ belongs_to :car, touch: true
185
+ end
186
+
187
+ car_1 = Car.create
188
+ car_2 = Car.create
189
+
190
+ passenger = Passenger.create car: car_1
191
+
192
+ passenger.car = car_2
193
+ passenger.save
194
+
195
+ Previously only car_2 would be touched. Now both car_1 and car_2
196
+ will be touched.
197
+
198
+ *Adam Gamble*
199
+
200
+ * Extract and deprecate Firebird / Sqlserver / Oracle database tasks, because
201
+ These tasks should be supported by 3rd-party adapter.
202
+
203
+ *kennyj*
204
+
205
+ * Allow `ActiveRecord::Base.connection_handler` to have thread affinity and be
206
+ settable, this effectively allows Active Record to be used in a multithreaded
207
+ setup with multiple connections to multiple databases.
208
+
209
+ *Sam Saffron*
210
+
211
+ * `rename_column` preserves `auto_increment` in MySQL migrations.
212
+ Fixes #3493.
213
+
214
+ *Vipul A M*
215
+
216
+ * PostgreSQL geometric type point is now supported by Active Record. Fixes #7324.
217
+
218
+ *Martin Schuerrer*
219
+
220
+ * Add support for concurrent indexing in PostgreSQL adapter via the
221
+ `algorithm: :concurrently` option.
222
+
223
+ add_index(:people, :last_name, algorithm: :concurrently)
224
+
225
+ Also add support for MySQL index algorithms (`COPY`, `INPLACE`,
226
+ `DEFAULT`) via the `:algorithm` option.
227
+
228
+ add_index(:people, :last_name, algorithm: :copy) # or :inplace/:default
229
+
230
+ *Dan McClain*
231
+
232
+ * Add support for fulltext and spatial indexes on MySQL tables with MyISAM database
233
+ engine via the `type: 'FULLTEXT'` / `type: 'SPATIAL'` option.
234
+
235
+ add_index(:people, :last_name, type: 'FULLTEXT')
236
+ add_index(:people, :last_name, type: 'SPATIAL')
237
+
238
+ *Ken Mazaika*
239
+
240
+ * Add an `add_index` override in PostgreSQL adapter and MySQL adapter
241
+ to allow custom index type support.
242
+ Fixes #6101.
243
+
244
+ add_index(:wikis, :body, :using => 'gin')
245
+
246
+ *Stefan Huber* and *Doabit*
247
+
248
+ * After extraction of mass-assignment attributes (which protects [id, type]
249
+ by default) we can pass id to `update_attributes` and it will update
250
+ another record because id will be used in where statement. We never have
251
+ to change id in where statement because we try to set/replace fields for
252
+ already loaded record but we have to try to set new id for that record.
253
+
254
+ *Dmitry Vorotilin*
255
+
256
+ * Models with multiple counter cache associations now update correctly on destroy.
257
+ See #7706.
258
+
259
+ *Ian Young*
260
+
261
+ * If `:inverse_of` is true on an association, then when one calls `find()` on
262
+ the association, Active Record will first look through the in-memory objects
263
+ in the association for a particular id. Then, it will go to the DB if it
264
+ is not found. This is accomplished by calling `find_by_scan` in
265
+ collection associations whenever `options[:inverse_of]` is not nil.
266
+ Fixes #9470.
267
+
268
+ *John Wang*
269
+
270
+ * `rake db:create` does not change permissions of the MySQL root user.
271
+ Fixes #8079.
272
+
273
+ *Yves Senn*
274
+
275
+ * The length of the `version` column in the `schema_migrations` table
276
+ created by the `mysql2` adapter is 191 if the encoding is "utf8mb4".
277
+
278
+ The "utf8" encoding in MySQL has support for a maximum of 3 bytes per character,
279
+ and only contains characters from the BMP. The recently added
280
+ [utf8mb4](http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8mb4.html)
281
+ encoding extends the support to four bytes. As of this writing, said encoding
282
+ is supported in the betas of the `mysql2` gem.
283
+
284
+ Setting the encoding to "utf8mb4" has
285
+ [a few implications](http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-upgrading.html).
286
+ This change addresses the max length for indexes, which is 191 instead of 255.
287
+
288
+ *Xavier Noria*
289
+
290
+ * Counter caches on associations will now stay valid when attributes are
291
+ updated (not just when records are created or destroyed), for example,
292
+ when calling `update_attributes`. The following code now works:
293
+
294
+ class Comment < ActiveRecord::Base
295
+ belongs_to :post, counter_cache: true
296
+ end
297
+
298
+ class Post < ActiveRecord::Base
299
+ has_many :comments
300
+ end
301
+
302
+ post = Post.create
303
+ comment = Comment.create
304
+
305
+ post.comments << comment
306
+ post.save.reload.comments_count # => 1
307
+ comment.update_attributes(post_id: nil)
308
+
309
+ post.save.reload.comments_count # => 0
310
+
311
+ Updating the id of a `belongs_to` object with the id of a new object will
312
+ also keep the count accurate.
313
+
314
+ *John Wang*
315
+
316
+ * Referencing join tables implicitly was deprecated. There is a
317
+ possibility that these deprecation warnings are shown even if you
318
+ don't make use of that feature. You can now disable the feature entirely.
319
+ Fixes #9712.
320
+
321
+ Example:
322
+
323
+ # in your configuration
324
+ config.active_record.disable_implicit_join_references = true
325
+
326
+ # or directly
327
+ ActiveRecord::Base.disable_implicit_join_references = true
328
+
329
+ *Yves Senn*
330
+
331
+ * The `:distinct` option for `Relation#count` is deprecated. You
332
+ should use `Relation#distinct` instead.
333
+
334
+ Example:
335
+
336
+ # Before
337
+ Post.select(:author_name).count(distinct: true)
338
+
339
+ # After
340
+ Post.select(:author_name).distinct.count
341
+
342
+ *Yves Senn*
343
+
344
+ * Rename `Relation#uniq` to `Relation#distinct`. `#uniq` is still
345
+ available as an alias but we encourage to use `#distinct` instead.
346
+ Also `Relation#uniq_value` is aliased to `Relation#distinct_value`,
347
+ this is a temporary solution and you should migrate to `distinct_value`.
348
+
349
+ *Yves Senn*
350
+
351
+ * Fix quoting for sqlite migrations using `copy_table_contents` with binary
352
+ columns.
353
+
354
+ These would fail with "SQLite3::SQLException: unrecognized token" because
355
+ the column was not being passed to `quote` so the data was not quoted
356
+ correctly.
357
+
358
+ *Matthew M. Boedicker*
359
+
360
+ * Promotes `change_column_null` to the migrations API. This macro sets/removes
361
+ `NOT NULL` constraints, and accepts an optional argument to replace existing
362
+ `NULL`s if needed. The adapters for SQLite, MySQL, PostgreSQL, and (at least)
363
+ Oracle, already implement this method.
364
+
365
+ *Xavier Noria*
366
+
367
+ * Uniqueness validation allows you to pass `:conditions` to limit
368
+ the constraint lookup.
369
+
370
+ Example:
371
+
372
+ validates_uniqueness_of :title, conditions: -> { where('approved = ?', true) }
373
+
374
+ *Mattias Pfeiffer + Yves Senn*
375
+
376
+ * `connection` is deprecated as an instance method.
377
+ This allows end-users to have a `connection` method on their models
378
+ without clashing with Active Record internals.
379
+
380
+ *Ben Moss*
381
+
382
+ * When copying migrations, preserve their magic comments and content encoding.
383
+
384
+ *OZAWA Sakuro*
385
+
386
+ * Fix `subclass_from_attrs` when `eager_load` is false. It cannot find
387
+ subclass because all classes are loaded automatically when it needs.
388
+
389
+ *Dmitry Vorotilin*
390
+
391
+ * When `:name` option is provided to `remove_index`, use it if there is no
392
+ index by the conventional name.
393
+
394
+ For example, previously if an index was removed like so
395
+ `remove_index :values, column: :value, name: 'a_different_name'`
396
+ the generated SQL would not contain the specified index name,
397
+ and hence the migration would fail.
398
+ Fixes #8858.
399
+
400
+ *Ezekiel Smithburg*
401
+
402
+ * Created block to by-pass the prepared statement bindings.
403
+ This will allow to compose fragments of large SQL statements to
404
+ avoid multiple round-trips between Ruby and the DB.
405
+
406
+ Example:
407
+
408
+ sql = Post.connection.unprepared_statement do
409
+ Post.first.comments.to_sql
410
+ end
411
+
412
+ *Cédric Fabianski*
413
+
414
+ * Change the semantics of combining scopes to be the same as combining
415
+ class methods which return scopes. For example:
416
+
417
+ class User < ActiveRecord::Base
418
+ scope :active, -> { where state: 'active' }
419
+ scope :inactive, -> { where state: 'inactive' }
420
+ end
421
+
422
+ class Post < ActiveRecord::Base
423
+ def self.active
424
+ where state: 'active'
425
+ end
426
+
427
+ def self.inactive
428
+ where state: 'inactive'
429
+ end
430
+ end
431
+
432
+ ### BEFORE ###
433
+
434
+ User.where(state: 'active').where(state: 'inactive')
435
+ # => SELECT * FROM users WHERE state = 'active' AND state = 'inactive'
436
+
437
+ User.active.inactive
438
+ # => SELECT * FROM users WHERE state = 'inactive'
439
+
440
+ Post.active.inactive
441
+ # => SELECT * FROM posts WHERE state = 'active' AND state = 'inactive'
442
+
443
+ ### AFTER ###
444
+
445
+ User.active.inactive
446
+ # => SELECT * FROM posts WHERE state = 'active' AND state = 'inactive'
447
+
448
+ Before this change, invoking a scope would merge it into the current
449
+ scope and return the result. `Relation#merge` applies "last where
450
+ wins" logic to de-duplicate the conditions, but this lead to
451
+ confusing and inconsistent behaviour. This fixes that.
452
+
453
+ If you really do want the "last where wins" logic, you can opt-in to
454
+ it like so:
455
+
456
+ User.active.merge(User.inactive)
457
+
458
+ Fixes #7365.
459
+
460
+ *Neeraj Singh* and *Jon Leighton*
461
+
462
+ * Expand `#cache_key` to consult all relevant updated timestamps.
463
+
464
+ Previously only `updated_at` column was checked, now it will
465
+ consult other columns that received updated timestamps on save,
466
+ such as `updated_on`. When multiple columns are present it will
467
+ use the most recent timestamp.
468
+ Fixes #9033.
469
+
470
+ *Brendon Murphy*
471
+
472
+ * Throw `NotImplementedError` when trying to instantiate `ActiveRecord::Base` or an abstract class.
473
+
474
+ *Aaron Weiner*
475
+
476
+ * Warn when `rake db:structure:dump` with a MySQL database and
477
+ `mysqldump` is not in the PATH or fails.
478
+ Fixes #9518.
479
+
480
+ *Yves Senn*
481
+
482
+ * Remove `connection#structure_dump`, which is no longer used. *Yves Senn*
483
+
484
+ * Make it possible to execute migrations without a transaction even
485
+ if the database adapter supports DDL transactions.
486
+ Fixes #9483.
487
+
488
+ Example:
489
+
490
+ class ChangeEnum < ActiveRecord::Migration
491
+ disable_ddl_transaction!
492
+
493
+ def up
494
+ execute "ALTER TYPE model_size ADD VALUE 'new_value'"
495
+ end
496
+ end
497
+
498
+ *Yves Senn*
499
+
500
+ * Assigning "0.0" to a nullable numeric column does not make it dirty.
501
+ Fixes #9034.
502
+
503
+ Example:
504
+
505
+ product = Product.create price: 0.0
506
+ product.price = '0.0'
507
+ product.changed? # => false (this used to return true)
508
+ product.changes # => {} (this used to return { price: [0.0, 0.0] })
509
+
510
+ *Yves Senn*
511
+
512
+ * Added functionality to unscope relations in a relations chain. For
513
+ instance, if you are passed in a chain of relations as follows:
514
+
515
+ User.where(name: "John").order('id DESC')
516
+
517
+ but you want to get rid of order, then this feature allows you to do:
518
+
519
+ User.where(name: "John").order('id DESC').unscope(:order)
520
+ == User.where(name: "John")
521
+
522
+ The .unscope() function is more general than the .except() method because
523
+ .except() only works on the relation it is acting on. However, .unscope()
524
+ works for any relation in the entire relation chain.
525
+
526
+ *John Wang*
527
+
528
+ * PostgreSQL timestamp with time zone (timestamptz) datatype now returns a
529
+ ActiveSupport::TimeWithZone instance instead of a string
530
+
531
+ *Troy Kruthoff*
532
+
533
+ * The `#append` method for collection associations behaves like`<<`.
534
+ `#prepend` is not defined and `<<` or `#append` should be used.
535
+ Fixes #7364.
536
+
537
+ *Yves Senn*
538
+
539
+ * Added support for creating a table via Rails migration generator.
540
+ For example,
541
+
542
+ rails g migration create_books title:string content:text
543
+
544
+ will generate a migration that creates a table called books with
545
+ the listed attributes, without creating a model.
546
+
547
+ *Sammy Larbi*
548
+
549
+ * Fix bug that raises the wrong exception when the exception handled by PostgreSQL adapter
550
+ doesn't respond to `#result`.
551
+ Fixes #8617.
552
+
553
+ *kennyj*
554
+
555
+ * Support PostgreSQL specific column types when using `change_table`.
556
+ Fixes #9480.
557
+
558
+ Example:
559
+
560
+ change_table :authors do |t|
561
+ t.hstore :books
562
+ t.json :metadata
563
+ end
564
+
565
+ *Yves Senn*
566
+
567
+ * Revert 408227d9c5ed7d, 'quote numeric'. This introduced some regressions.
568
+
569
+ *Steve Klabnik*
570
+
571
+ * Fix calculation of `db_runtime` property in
572
+ `ActiveRecord::Railties::ControllerRuntime#cleanup_view_runtime`.
573
+ Previously, after raising `ActionView::MissingTemplate`, `db_runtime` was
574
+ not populated.
575
+ Fixes #9215.
576
+
577
+ *Igor Fedoronchuk*
578
+
579
+ * Do not try to touch invalid (and thus not persisted) parent record
580
+ for a `belongs_to :parent, touch: true` association
581
+
582
+ *Olek Janiszewski*
583
+
584
+ * Fix when performing an ordered join query. The bug only
585
+ affected queries where the order was given with a symbol.
586
+ Fixes #9275.
587
+
588
+ Example:
589
+
590
+ # This will expand the order :name to "authors".name.
591
+ Author.joins(:books).where('books.published = 1').order(:name)
592
+
593
+ * Fix overriding of attributes by `default_scope` on `ActiveRecord::Base#dup`.
594
+
595
+ *Hiroshige UMINO*
596
+
597
+ * Update queries now use prepared statements.
598
+
599
+ *Olli Rissanen*
600
+
601
+ * Fixing issue #8345. Now throwing an error when one attempts to touch a
602
+ new object that has not yet been persisted. For instance:
603
+
604
+ Example:
605
+
606
+ ball = Ball.new
607
+ ball.touch :updated_at # => raises error
608
+
609
+ It is not until the ball object has been persisted that it can be touched.
610
+ This follows the behavior of update_column.
611
+
612
+ *John Wang*
613
+
614
+ * Preloading ordered `has_many :through` associations no longer applies
615
+ invalid ordering to the `:through` association.
616
+ Fixes #8663.
617
+
618
+ *Yves Senn*
619
+
620
+ * The auto explain feature has been removed. This feature was
621
+ activated by configuring `config.active_record.auto_explain_threshold_in_seconds`.
622
+ The configuration option was deprecated and has no more effect.
623
+
624
+ You can still use `ActiveRecord::Relation#explain` to see the EXPLAIN output for
625
+ any given relation.
626
+
627
+ *Yves Senn*
628
+
629
+ * The `:on` option for `after_commit` and `after_rollback` now
630
+ accepts an Array of actions.
631
+ Fixes #988.
632
+
633
+ Example:
634
+
635
+ after_commit :update_cache on: [:create, :update]
636
+
637
+ *Yves Senn*
638
+
639
+ * Rename related indexes on `rename_table` and `rename_column`. This
640
+ does not affect indexes with custom names.
641
+
642
+ *Yves Senn*
643
+
644
+ * Prevent the creation of indices with too long names, which cause
645
+ internal operations to fail (sqlite3 adapter only). The method
646
+ `allowed_index_name_length` defines the length limit enforced by
647
+ rails. It's value defaults to `index_name_length` but can vary per adapter.
648
+ Fixes #8264.
649
+
650
+ *Yves Senn*
651
+
652
+ * Fixing issue #776.
653
+
654
+ Memory bloat in transactions is handled by having the transaction hold only
655
+ the AR objects which it absolutely needs to know about. These are the AR
656
+ objects with callbacks (they need to be updated as soon as something in the
657
+ transaction occurs).
658
+
659
+ All other AR objects can be updated lazily by keeping a reference to a
660
+ TransactionState object. If an AR object gets inside a transaction, then
661
+ the transaction will add its TransactionState to the AR object. When the
662
+ user makes a call to some attribute on an AR object (which has no
663
+ callbacks) associated with a transaction, the AR object will call the
664
+ sync_with_transaction_state method and make sure it is up to date with the
665
+ transaction. After it has synced with the transaction state, the AR object
666
+ will return the attribute that was requested.
667
+
668
+ Most of the logic in the changes are used to handle multiple transactions,
669
+ in which case the AR object has to recursively follow parent pointers of
670
+ TransactionState objects.
671
+
672
+ *John Wang*
673
+
674
+ * Descriptive error message when the necessary AR adapter gem was not found.
675
+ Fixes #7313.
676
+
677
+ *Yves Senn*
678
+
679
+ * Active Record now raises an error when blank arguments are passed to query
680
+ methods for which blank arguments do not make sense.
681
+
682
+ Example:
683
+
684
+ Post.includes() # => raises error
685
+
686
+ *John Wang*
687
+
688
+ * Simplified type casting code for timezone aware attributes to use the
689
+ `in_time_zone` method if it is available. This introduces a subtle change
690
+ of behavior when using `Date` instances as they are directly converted to
691
+ `ActiveSupport::TimeWithZone` instances without first being converted to
692
+ `Time` instances. For example:
693
+
694
+ # Rails 3.2 behavior
695
+ >> Date.today.to_time.in_time_zone
696
+ => Wed, 13 Feb 2013 07:00:00 UTC +00:00
697
+
698
+ # Rails 4.0 behavior
699
+ >> Date.today.in_time_zone
700
+ => Wed, 13 Feb 2013 00:00:00 UTC +00:00
701
+
702
+ On the plus side it now behaves the same whether you pass a `String` date
703
+ or an actual `Date` instance. For example:
704
+
705
+ # Rails 3.2 behavior
706
+ >> Date.civil(2013, 2, 13).to_time.in_time_zone
707
+ => Wed, 13 Feb 2013 07:00:00 UTC +00:00
708
+ >> Time.zone.parse("2013-02-13")
709
+ => Wed, 13 Feb 2013 00:00:00 UTC +00:00
710
+
711
+ # Rails 4.0 behavior
712
+ >> Date.civil(2013, 2, 13).in_time_zone
713
+ => Wed, 13 Feb 2013 00:00:00 UTC +00:00
714
+ >> "2013-02-13".in_time_zone
715
+ => Wed, 13 Feb 2013 00:00:00 UTC +00:00
716
+
717
+ If you need the old behavior you can convert the dates to times manually.
718
+ For example:
719
+
720
+ >> Post.new(created_at: Date.today).created_at
721
+ => Wed, 13 Feb 2013 00:00:00 UTC +00:00
722
+
723
+ >> Post.new(created_at: Date.today.to_time).created_at
724
+ => Wed, 13 Feb 2013 07:00:00 UTC +00:00
725
+
726
+ *Andrew White*
727
+
728
+ * Preloading `has_many :through` associations with conditions won't
729
+ cache the `:through` association. This will prevent invalid
730
+ subsets to be cached.
731
+ Fixes #8423.
732
+
733
+ Example:
734
+
735
+ class User
736
+ has_many :posts
737
+ has_many :recent_comments, -> { where('created_at > ?', 1.week.ago) }, :through => :posts
738
+ end
739
+
740
+ a_user = User.includes(:recent_comments).first
741
+
742
+ # This is preloaded.
743
+ a_user.recent_comments
744
+
745
+ # This is not preloaded, fetched now.
746
+ a_user.posts
747
+
748
+ *Yves Senn*
749
+
750
+ * Don't run `after_commit` callbacks when creating through an association
751
+ if saving the record fails.
752
+
753
+ *James Miller*
754
+
755
+ * Allow store accessors to be overridden like other attribute methods, e.g.:
756
+
757
+ class User < ActiveRecord::Base
758
+ store :settings, accessors: [ :color, :homepage ], coder: JSON
759
+
760
+ def color
761
+ super || 'red'
762
+ end
763
+ end
764
+
765
+ *Sergey Nartimov*
766
+
767
+ * Quote numeric values being compared to non-numeric columns. Otherwise,
768
+ in some database, the string column values will be coerced to a numeric
769
+ allowing 0, 0.0 or false to match any string starting with a non-digit.
770
+
771
+ Example:
772
+
773
+ App.where(apikey: 0) # => SELECT * FROM users WHERE apikey = '0'
774
+
775
+ *Dylan Smith*
776
+
777
+ * Schema dumper supports dumping the enabled database extensions to `schema.rb`
778
+ (currently only supported by PostgreSQL).
779
+
780
+ *Justin George*
781
+
782
+ * The database adapters now converts the options passed thought `DATABASE_URL`
783
+ environment variable to the proper Ruby types before using. For example, SQLite requires
784
+ that the timeout value is an integer, and PostgreSQL requires that the
785
+ prepared_statements option is a boolean. These now work as expected:
786
+
787
+ Example:
788
+
789
+ DATABASE_URL=sqlite3://localhost/test_db?timeout=500
790
+ DATABASE_URL=postgresql://localhost/test_db?prepared_statements=false
791
+
792
+ *Aaron Stone + Rafael Mendonça França*
793
+
794
+ * `Relation#merge` now only overwrites where values on the LHS of the
795
+ merge. Consider:
796
+
797
+ left = Person.where(age: [13, 14, 15])
798
+ right = Person.where(age: [13, 14]).where(age: [14, 15])
799
+
800
+ `left` results in the following SQL:
801
+
802
+ WHERE age IN (13, 14, 15)
803
+
804
+ `right` results in the following SQL:
805
+
806
+ WHERE age IN (13, 14) AND age IN (14, 15)
807
+
808
+ Previously, `left.merge(right)` would result in all but the last
809
+ condition being removed:
810
+
811
+ WHERE age IN (14, 15)
812
+
813
+ Now it results in the LHS condition(s) for `age` being removed, but
814
+ the RHS remains as it is:
815
+
816
+ WHERE age IN (13, 14) AND age IN (14, 15)
817
+
818
+ *Jon Leighton*
819
+
820
+ * Fix handling of dirty time zone aware attributes
821
+
822
+ Previously, when `time_zone_aware_attributes` were enabled, after
823
+ changing a datetime or timestamp attribute and then changing it back
824
+ to the original value, `changed_attributes` still tracked the
825
+ attribute as changed. This caused `[attribute]_changed?` and
826
+ `changed?` methods to return true incorrectly.
827
+
828
+ Example:
829
+
830
+ in_time_zone 'Paris' do
831
+ order = Order.new
832
+ original_time = Time.local(2012, 10, 10)
833
+ order.shipped_at = original_time
834
+ order.save
835
+ order.changed? # => false
836
+
837
+ # changing value
838
+ order.shipped_at = Time.local(2013, 1, 1)
839
+ order.changed? # => true
840
+
841
+ # reverting to original value
842
+ order.shipped_at = original_time
843
+ order.changed? # => false, used to return true
844
+ end
845
+
846
+ *Lilibeth De La Cruz*
847
+
848
+ * When `#count` is used in conjunction with `#uniq` we perform `count(:distinct => true)`.
849
+ Fixes #6865.
850
+
851
+ Example:
852
+
853
+ relation.uniq.count # => SELECT COUNT(DISTINCT *)
854
+
855
+ *Yves Senn + Kaspar Schiess*
856
+
857
+ * PostgreSQL ranges type support. Includes: int4range, int8range,
858
+ numrange, tsrange, tstzrange, daterange
859
+
860
+ Ranges can be created with inclusive and exclusive bounds.
861
+
862
+ Example:
863
+
864
+ create_table :Room do |t|
865
+ t.daterange :availability
866
+ end
867
+
868
+ Room.create(availability: (Date.today..Float::INFINITY))
869
+ Room.first.availability # => Wed, 19 Sep 2012..Infinity
870
+
871
+ One thing to note: Range class does not support exclusive lower
872
+ bound.
873
+
874
+ *Alexander Grebennik*
875
+
876
+ * Added a state instance variable to each transaction. Will allow other objects
877
+ to know whether a transaction has been committed or rolled back.
878
+
879
+ *John Wang*
880
+
881
+ * Collection associations `#empty?` always respects built records.
882
+ Fixes #8879.
883
+
884
+ Example:
885
+
886
+ widget = Widget.new
887
+ widget.things.build
888
+ widget.things.empty? # => false
889
+
890
+ *Yves Senn*
891
+
892
+ * Support for PostgreSQL's `ltree` data type.
893
+
894
+ *Rob Worley*
895
+
896
+ * Fix undefined method `to_i` when calling `new` on a scope that uses an
897
+ Array; Fix FloatDomainError when setting integer column to NaN.
898
+ Fixes #8718, #8734, #8757.
899
+
900
+ *Jason Stirk + Tristan Harward*
901
+
902
+ * Rename `update_attributes` to `update`, keep `update_attributes` as an alias for `update` method.
903
+ This is a soft-deprecation for `update_attributes`, although it will still work without any
904
+ deprecation message in 4.0 is recommended to start using `update` since `update_attributes` will be
905
+ deprecated and removed in future versions of Rails.
906
+
907
+ *Amparo Luna + Guillermo Iguaran*
908
+
909
+ * `after_commit` and `after_rollback` now validate the `:on` option and raise an `ArgumentError`
910
+ if it is not one of `:create`, `:destroy` or `:update`
911
+
912
+ *Pascal Friederich*
913
+
914
+ * Improve ways to write `change` migrations, making the old `up` & `down` methods no longer necessary.
915
+
916
+ * The methods `drop_table` and `remove_column` are now reversible, as long as the necessary information is given.
917
+ The method `remove_column` used to accept multiple column names; instead use `remove_columns` (which is not reversible).
918
+ The method `change_table` is also reversible, as long as its block doesn't call `remove`, `change` or `change_default`
919
+
920
+ * New method `reversible` makes it possible to specify code to be run when migrating up or down.
921
+ See the [Guide on Migration](https://github.com/rails/rails/blob/master/guides/source/migrations.md#using-the-reversible-method)
922
+
923
+ * New method `revert` will revert a whole migration or the given block.
924
+ If migrating down, the given migration / block is run normally.
925
+ See the [Guide on Migration](https://github.com/rails/rails/blob/master/guides/source/migrations.md#reverting-previous-migrations)
926
+
927
+ Attempting to revert the methods `execute`, `remove_columns` and `change_column` will now
928
+ raise an `IrreversibleMigration` instead of actually executing them without any output.
929
+
930
+ *Marc-André Lafortune*
931
+
932
+ * Serialized attributes can be serialized in integer columns.
933
+ Fixes #8575.
934
+
935
+ *Rafael Mendonça França*
936
+
937
+ * Keep index names when using `alter_table` with sqlite3.
938
+ Fixes #3489.
939
+
940
+ *Yves Senn*
941
+
942
+ * Add ability for PostgreSQL adapter to disable user triggers in `disable_referential_integrity`.
943
+ Fixes #5523.
944
+
945
+ *Gary S. Weaver*
946
+
947
+ * Added support for `validates_uniqueness_of` in PostgreSQL array columns.
948
+ Fixes #8075.
949
+
950
+ *Pedro Padron*
951
+
952
+ * Allow int4range and int8range columns to be created in PostgreSQL and properly convert to/from database.
953
+
954
+ *Alexey Vasiliev aka leopard*
955
+
956
+ * Do not log the binding values for binary columns.
957
+
958
+ *Matthew M. Boedicker*
959
+
960
+ * Fix counter cache columns not updated when replacing `has_many :through`
961
+ associations.
962
+
963
+ *Matthew Robertson*
964
+
965
+ * Recognize migrations placed in directories containing numbers and 'rb'.
966
+ Fixes #8492.
967
+
968
+ *Yves Senn*
969
+
970
+ * Add `ActiveRecord::Base.cache_timestamp_format` class attribute to control
971
+ the format of the timestamp value in the cache key. Defaults to `:nsec`.
972
+ Fixes #8195.
973
+
974
+ *Rafael Mendonça França*
975
+
976
+ * Session variables can be set for the `mysql`, `mysql2`, and `postgresql` adapters
977
+ in the `variables: <hash>` parameter in `config/database.yml`. The key-value pairs of this
978
+ hash will be sent in a `SET key = value` query on new database connections. See also:
979
+ http://dev.mysql.com/doc/refman/5.0/en/set-statement.html
980
+ http://www.postgresql.org/docs/8.3/static/sql-set.html
981
+
982
+ *Aaron Stone*
983
+
984
+ * Allow setting of all libpq connection parameters through the PostgreSQL adapter. See also:
985
+ http://www.postgresql.org/docs/9.2/static/libpq-connect.html#LIBPQ-PARAMKEYWORDS
986
+
987
+ *Lars Kanis*
988
+
989
+ * Allow `Relation#where` with no arguments to be chained with new `not` query method.
990
+
991
+ Example:
992
+
993
+ Developer.where.not(name: 'Aaron')
994
+
995
+ *Akira Matsuda*
996
+
997
+ * Unscope `update_column(s)` query to ignore default scope.
998
+
999
+ When applying `default_scope` to a class with a where clause, using
1000
+ `update_column(s)` could generate a query that would not properly update
1001
+ the record due to the where clause from the `default_scope` being applied
1002
+ to the update query.
1003
+
1004
+ class User < ActiveRecord::Base
1005
+ default_scope -> { where(active: true) }
1006
+ end
1007
+
1008
+ user = User.first
1009
+ user.active = false
1010
+ user.save!
1011
+
1012
+ user.update_column(:active, true) # => false
1013
+
1014
+ In this situation we want to skip the default_scope clause and just
1015
+ update the record based on the primary key. With this change:
1016
+
1017
+ user.update_column(:active, true) # => true
1018
+
1019
+ Fixes #8436.
1020
+
1021
+ *Carlos Antonio da Silva*
1022
+
1023
+ * SQLite adapter no longer corrupts binary data if the data contains `%00`.
1024
+
1025
+ *Chris Feist*
1026
+
1027
+ * Fix performance problem with `primary_key` method in PostgreSQL adapter when having many schemas.
1028
+ Uses `pg_constraint` table instead of `pg_depend` table which has many records in general.
1029
+ Fixes #8414.
1030
+
1031
+ *kennyj*
1032
+
1033
+ * Do not instantiate intermediate Active Record objects when eager loading.
1034
+ These records caused `after_find` to run more than expected.
1035
+ Fixes #3313.
1036
+
1037
+ *Yves Senn*
1038
+
1039
+ * Add STI support to init and building associations.
1040
+ Allows you to do `BaseClass.new(type: "SubClass")` as well as
1041
+ `parent.children.build(type: "SubClass")` or `parent.build_child`
1042
+ to initialize an STI subclass. Ensures that the class name is a
1043
+ valid class and that it is in the ancestors of the super class
1044
+ that the association is expecting.
1045
+
1046
+ *Jason Rush*
1047
+
1048
+ * Observers was extracted from Active Record as `rails-observers` gem.
1049
+
1050
+ *Rafael Mendonça França*
1051
+
1052
+ * Ensure that associations take a symbol argument. *Steve Klabnik*
1053
+
1054
+ * Fix dirty attribute checks for `TimeZoneConversion` with nil and blank
1055
+ datetime attributes. Setting a nil datetime to a blank string should not
1056
+ result in a change being flagged.
1057
+ Fixes #8310.
1058
+
1059
+ *Alisdair McDiarmid*
1060
+
1061
+ * Prevent mass assignment to the type column of polymorphic associations when using `build`
1062
+ Fixes #8265.
1063
+
1064
+ *Yves Senn*
1065
+
1066
+ * Deprecate calling `Relation#sum` with a block. To perform a calculation over
1067
+ the array result of the relation, use `to_a.sum(&block)`.
1068
+
1069
+ *Carlos Antonio da Silva*
1070
+
1071
+ * Fix PostgreSQL adapter to handle BC timestamps correctly
1072
+
1073
+ HistoryEvent.create!(name: "something", occured_at: Date.new(0) - 5.years)
1074
+
1075
+ *Bogdan Gusiev*
1076
+
1077
+ * When running migrations on PostgreSQL, the `:limit` option for `binary` and `text` columns is silently dropped.
1078
+ Previously, these migrations caused sql exceptions, because PostgreSQL doesn't support limits on these types.
1079
+
1080
+ *Victor Costan*
1081
+
1082
+ * Don't change STI type when calling `ActiveRecord::Base#becomes`.
1083
+ Add `ActiveRecord::Base#becomes!` with the previous behavior.
1084
+
1085
+ See #3023 for more information.
1086
+
1087
+ *Thomas Hollstegge*
1088
+
1089
+ * `rename_index` can be used inside a `change_table` block.
1090
+
1091
+ change_table :accounts do |t|
1092
+ t.rename_index :user_id, :account_id
1093
+ end
1094
+
1095
+ *Jarek Radosz*
1096
+
1097
+ * `#pluck` can be used on a relation with `select` clause. Fix #7551
1098
+
1099
+ Example:
1100
+
1101
+ Topic.select([:approved, :id]).order(:id).pluck(:id)
1102
+
1103
+ *Yves Senn*
1104
+
1105
+ * Do not create useless database transaction when building `has_one` association.
1106
+
1107
+ Example:
1108
+
1109
+ User.has_one :profile
1110
+ User.new.build_profile
1111
+
1112
+ *Bogdan Gusiev*
1113
+
1114
+ * `:counter_cache` option for `has_many` associations to support custom named counter caches.
1115
+ Fixes #7993.
1116
+
1117
+ *Yves Senn*
1118
+
1119
+ * Deprecate the possibility to pass a string as third argument of `add_index`.
1120
+ Pass `unique: true` instead.
1121
+
1122
+ add_index(:users, :organization_id, unique: true)
1123
+
1124
+ *Rafael Mendonça França*
1125
+
1126
+ * Raise an `ArgumentError` when passing an invalid option to `add_index`.
1127
+
1128
+ *Rafael Mendonça França*
1129
+
1130
+ * Fix `find_in_batches` crashing when IDs are strings and start option is not specified.
1131
+
1132
+ *Alexis Bernard*
1133
+
1134
+ * `AR::Base#attributes_before_type_cast` now returns unserialized values for serialized attributes.
1135
+
1136
+ *Nikita Afanasenko*
1137
+
1138
+ * Use query cache/uncache when using `DATABASE_URL`.
1139
+ Fixes #6951.
1140
+
1141
+ *kennyj*
1142
+
1143
+ * Fix bug where `update_columns` and `update_column` would not let you update the primary key column.
1144
+
1145
+ *Henrik Nyh*
1146
+
1147
+ * The `create_table` method raises an `ArgumentError` when the primary key column is redefined.
1148
+ Fixes #6378.
1149
+
1150
+ *Yves Senn*
1151
+
1152
+ * `ActiveRecord::AttributeMethods#[]` raises `ActiveModel::MissingAttributeError`
1153
+ error if the given attribute is missing. Fixes #5433.
1154
+
1155
+ class Person < ActiveRecord::Base
1156
+ belongs_to :company
1157
+ end
1158
+
1159
+ # Before:
1160
+ person = Person.select('id').first
1161
+ person[:name] # => nil
1162
+ person.name # => ActiveModel::MissingAttributeError: missing_attribute: name
1163
+ person[:company_id] # => nil
1164
+ person.company # => nil
1165
+
1166
+ # After:
1167
+ person = Person.select('id').first
1168
+ person[:name] # => ActiveModel::MissingAttributeError: missing_attribute: name
1169
+ person.name # => ActiveModel::MissingAttributeError: missing_attribute: name
1170
+ person[:company_id] # => ActiveModel::MissingAttributeError: missing_attribute: company_id
1171
+ person.company # => ActiveModel::MissingAttributeError: missing_attribute: company_id
1172
+
1173
+ *Francesco Rodriguez*
1174
+
1175
+ * Small binary fields use the `VARBINARY` MySQL type, instead of `TINYBLOB`.
1176
+
1177
+ *Victor Costan*
1178
+
1179
+ * Decode URI encoded attributes on database connection URLs.
1180
+
1181
+ *Shawn Veader*
1182
+
1183
+ * Add `find_or_create_by`, `find_or_create_by!` and
1184
+ `find_or_initialize_by` methods to `Relation`.
1185
+
1186
+ These are similar to the `first_or_create` family of methods, but
1187
+ the behaviour when a record is created is slightly different:
1188
+
1189
+ User.where(first_name: 'Penélope').first_or_create
1190
+
1191
+ will execute:
1192
+
1193
+ User.where(first_name: 'Penélope').create
1194
+
1195
+ Causing all the `create` callbacks to execute within the context of
1196
+ the scope. This could affect queries that occur within callbacks.
1197
+
1198
+ User.find_or_create_by(first_name: 'Penélope')
1199
+
1200
+ will execute:
1201
+
1202
+ User.create(first_name: 'Penélope')
1203
+
1204
+ Which obviously does not affect the scoping of queries within
1205
+ callbacks.
1206
+
1207
+ The `find_or_create_by` version also reads better, frankly.
1208
+
1209
+ If you need to add extra attributes during create, you can do one of:
1210
+
1211
+ User.create_with(active: true).find_or_create_by(first_name: 'Jon')
1212
+ User.find_or_create_by(first_name: 'Jon') { |u| u.active = true }
1213
+
1214
+ The `first_or_create` family of methods have been nodoc'ed in favour
1215
+ of this API. They may be deprecated in the future but their
1216
+ implementation is very small and it's probably not worth putting users
1217
+ through lots of annoying deprecation warnings.
1218
+
1219
+ *Jon Leighton*
1220
+
1221
+ * Fix bug with presence validation of associations. Would incorrectly add duplicated errors
1222
+ when the association was blank. Bug introduced in 1fab518c6a75dac5773654646eb724a59741bc13.
1223
+
1224
+ *Scott Willson*
1225
+
1226
+ * Fix bug where sum(expression) returns string '0' for no matching records.
1227
+ Fixes #7439
1228
+
1229
+ *Tim Macfarlane*
1230
+
1231
+ * PostgreSQL adapter correctly fetches default values when using multiple schemas and domains in a db. Fixes #7914
1232
+
1233
+ *Arturo Pie*
1234
+
1235
+ * Learn ActiveRecord::QueryMethods#order work with hash arguments
1236
+
1237
+ When symbol or hash passed we convert it to Arel::Nodes::Ordering.
1238
+ If we pass invalid direction(like name: :DeSc) ActiveRecord::QueryMethods#order will raise an exception
1239
+
1240
+ User.order(:name, email: :desc)
1241
+ # SELECT "users".* FROM "users" ORDER BY "users"."name" ASC, "users"."email" DESC
1242
+
1243
+ *Tima Maslyuchenko*
1244
+
1245
+ * Rename `ActiveRecord::Fixtures` class to `ActiveRecord::FixtureSet`.
1246
+ Instances of this class normally hold a collection of fixtures (records)
1247
+ loaded either from a single YAML file, or from a file and a folder
1248
+ with the same name. This change make the class name singular and makes
1249
+ the class easier to distinguish from the modules like
1250
+ `ActiveRecord::TestFixtures`, which operates on multiple fixture sets,
1251
+ or `DelegatingFixtures`, `::Fixtures`, etc.,
1252
+ and from the class `ActiveRecord::Fixture`, which corresponds to a single
1253
+ fixture.
1254
+
1255
+ *Alexey Muranov*
1256
+
1257
+ * The postgres adapter now supports tables with capital letters.
1258
+ Fixes #5920.
1259
+
1260
+ *Yves Senn*
1261
+
1262
+ * `CollectionAssociation#count` returns `0` without querying if the
1263
+ parent record is not persisted.
1264
+
1265
+ Before:
1266
+
1267
+ person.pets.count
1268
+ # SELECT COUNT(*) FROM "pets" WHERE "pets"."person_id" IS NULL
1269
+ # => 0
1270
+
1271
+ After:
1272
+
1273
+ person.pets.count
1274
+ # fires without sql query
1275
+ # => 0
1276
+
1277
+ *Francesco Rodriguez*
1278
+
1279
+ * Fix `reset_counters` crashing on `has_many :through` associations.
1280
+ Fixes #7822.
1281
+
1282
+ *lulalala*
1283
+
1284
+ * Support for partial inserts.
1285
+
1286
+ When inserting new records, only the fields which have been changed
1287
+ from the defaults will actually be included in the INSERT statement.
1288
+ The other fields will be populated by the database.
1289
+
1290
+ This is more efficient, and also means that it will be safe to
1291
+ remove database columns without getting subsequent errors in running
1292
+ app processes (so long as the code in those processes doesn't
1293
+ contain any references to the removed column).
1294
+
1295
+ The `partial_updates` configuration option is now renamed to
1296
+ `partial_writes` to reflect the fact that it now impacts both inserts
1297
+ and updates.
1298
+
1299
+ *Jon Leighton*
1300
+
1301
+ * Allow before and after validations to take an array of lifecycle events
1302
+
1303
+ *John Foley*
1304
+
1305
+ * Support for specifying transaction isolation level
1306
+
1307
+ If your database supports setting the isolation level for a transaction, you can set
1308
+ it like so:
1309
+
1310
+ Post.transaction(isolation: :serializable) do
1311
+ # ...
1312
+ end
1313
+
1314
+ Valid isolation levels are:
1315
+
1316
+ * `:read_uncommitted`
1317
+ * `:read_committed`
1318
+ * `:repeatable_read`
1319
+ * `:serializable`
1320
+
1321
+ You should consult the documentation for your database to understand the
1322
+ semantics of these different levels:
1323
+
1324
+ * http://www.postgresql.org/docs/9.1/static/transaction-iso.html
1325
+ * https://dev.mysql.com/doc/refman/5.0/en/set-transaction.html
1326
+
1327
+ An `ActiveRecord::TransactionIsolationError` will be raised if:
1328
+
1329
+ * The adapter does not support setting the isolation level
1330
+ * You are joining an existing open transaction
1331
+ * You are creating a nested (savepoint) transaction
1332
+
1333
+ The mysql, mysql2 and postgresql adapters support setting the transaction
1334
+ isolation level. However, support is disabled for mysql versions below 5,
1335
+ because they are affected by a bug (http://bugs.mysql.com/bug.php?id=39170)
1336
+ which means the isolation level gets persisted outside the transaction.
1337
+
1338
+ *Jon Leighton*
1339
+
1340
+ * `ActiveModel::ForbiddenAttributesProtection` is included by default
1341
+ in Active Record models. Check the docs of `ActiveModel::ForbiddenAttributesProtection`
1342
+ for more details.
1343
+
1344
+ *Guillermo Iguaran*
1345
+
1346
+ * Remove integration between Active Record and
1347
+ `ActiveModel::MassAssignmentSecurity`, `protected_attributes` gem
1348
+ should be added to use `attr_accessible`/`attr_protected`. Mass
1349
+ assignment options has been removed from all the AR methods that
1350
+ used it (ex. `AR::Base.new`, `AR::Base.create`, `AR::Base#update_attributes`, etc).
1351
+
1352
+ *Guillermo Iguaran*
1353
+
1354
+ * Fix the return of querying with an empty hash.
1355
+ Fixes #6971.
1356
+
1357
+ User.where(token: {})
1358
+
1359
+ Before:
1360
+
1361
+ #=> SELECT * FROM users;
1362
+
1363
+ After:
1364
+
1365
+ #=> SELECT * FROM users WHERE 1=0;
1366
+
1367
+ *Damien Mathieu*
1368
+
1369
+ * Fix creation of through association models when using `collection=[]`
1370
+ on a `has_many :through` association from an unsaved model.
1371
+ Fixes #7661.
1372
+
1373
+ *Ernie Miller*
1374
+
1375
+ * Explain only normal CRUD sql (select / update / insert / delete).
1376
+ Fix problem that explains unexplainable sql.
1377
+ Fixes #7544 #6458.
1378
+
1379
+ *kennyj*
1380
+
1381
+ * You can now override the generated accessor methods for stored attributes
1382
+ and reuse the original behavior with `read_store_attribute` and `write_store_attribute`,
1383
+ which are counterparts to `read_attribute` and `write_attribute`.
1384
+
1385
+ *Matt Jones*
1386
+
1387
+ * Accept `belongs_to` (including polymorphic) association keys in queries.
1388
+
1389
+ The following queries are now equivalent:
1390
+
1391
+ Post.where(author: author)
1392
+ Post.where(author_id: author)
1393
+
1394
+ PriceEstimate.where(estimate_of: treasure)
1395
+ PriceEstimate.where(estimate_of_type: 'Treasure', estimate_of_id: treasure)
1396
+
1397
+ *Peter Brown*
1398
+
1399
+ * Use native `mysqldump` command instead of `structure_dump` method
1400
+ when dumping the database structure to a sql file. Fixes #5547.
1401
+
1402
+ *kennyj*
1403
+
1404
+ * PostgreSQL inet and cidr types are converted to `IPAddr` objects.
1405
+
1406
+ *Dan McClain*
1407
+
1408
+ * PostgreSQL array type support. Any datatype can be used to create an
1409
+ array column, with full migration and schema dumper support.
1410
+
1411
+ To declare an array column, use the following syntax:
1412
+
1413
+ create_table :table_with_arrays do |t|
1414
+ t.integer :int_array, array: true
1415
+ # integer[]
1416
+ t.integer :int_array, array: true, length: 2
1417
+ # smallint[]
1418
+ t.string :string_array, array: true, length: 30
1419
+ # char varying(30)[]
1420
+ end
1421
+
1422
+ This respects any other migration detail (limits, defaults, etc).
1423
+ Active Record will serialize and deserialize the array columns on
1424
+ their way to and from the database.
1425
+
1426
+ One thing to note: PostgreSQL does not enforce any limits on the
1427
+ number of elements, and any array can be multi-dimensional. Any
1428
+ array that is multi-dimensional must be rectangular (each sub array
1429
+ must have the same number of elements as its siblings).
1430
+
1431
+ If the `pg_array_parser` gem is available, it will be used when
1432
+ parsing PostgreSQL's array representation.
1433
+
1434
+ *Dan McClain*
1435
+
1436
+ * Attribute predicate methods, such as `article.title?`, will now raise
1437
+ `ActiveModel::MissingAttributeError` if the attribute being queried for
1438
+ truthiness was not read from the database, instead of just returning `false`.
1439
+
1440
+ *Ernie Miller*
1441
+
1442
+ * `ActiveRecord::SchemaDumper` uses Ruby 1.9 style hash, which means that the
1443
+ schema.rb file will be generated using this new syntax from now on.
1444
+
1445
+ *Konstantin Shabanov*
1446
+
1447
+ * Map interval with precision to string datatype in PostgreSQL. Fixes #7518.
1448
+
1449
+ *Yves Senn*
1450
+
1451
+ * Fix eagerly loading associations without primary keys. Fixes #4976.
1452
+
1453
+ *Kelley Reynolds*
1454
+
1455
+ * Rails now raise an exception when you're trying to run a migration that has an invalid
1456
+ file name. Only lower case letters, numbers, and '_' are allowed in migration's file name.
1457
+ Please see #7419 for more details.
1458
+
1459
+ *Jan Bernacki*
1460
+
1461
+ * Fix bug when calling `store_accessor` multiple times.
1462
+ Fixes #7532.
1463
+
1464
+ *Matt Jones*
1465
+
1466
+ * Fix store attributes that show the changes incorrectly.
1467
+ Fixes #7532.
1468
+
1469
+ *Matt Jones*
1470
+
1471
+ * Fix `ActiveRecord::Relation#pluck` when columns or tables are reserved words.
1472
+
1473
+ *Ian Lesperance*
1474
+
1475
+ * Allow JSON columns to be created in PostgreSQL and properly encoded/decoded.
1476
+ to/from database.
1477
+
1478
+ *Dickson S. Guedes*
1479
+
1480
+ * Fix time column type casting for invalid time string values to correctly return `nil`.
1481
+
1482
+ *Adam Meehan*
1483
+
1484
+ * Allow to pass Symbol or Proc into `:limit` option of #accepts_nested_attributes_for.
1485
+
1486
+ *Mikhail Dieterle*
1487
+
1488
+ * ActiveRecord::SessionStore has been extracted from Active Record as `activerecord-session_store`
1489
+ gem. Please read the `README.md` file on the gem for the usage.
1490
+
1491
+ *Prem Sichanugrist*
1492
+
1493
+ * Fix `reset_counters` when there are multiple `belongs_to` association with the
1494
+ same foreign key and one of them have a counter cache.
1495
+ Fixes #5200.
1496
+
1497
+ *Dave Desrochers*
1498
+
1499
+ * `serialized_attributes` and `_attr_readonly` become class method only. Instance reader methods are deprecated.
1500
+
1501
+ *kennyj*
1502
+
1503
+ * Round usec when comparing timestamp attributes in the dirty tracking.
1504
+ Fixes #6975.
1505
+
1506
+ *kennyj*
1507
+
1508
+ * Use inversed parent for first and last child of `has_many` association.
1509
+
1510
+ *Ravil Bayramgalin*
1511
+
1512
+ * Fix `Column.microseconds` and `Column.fast_string_to_time` to avoid converting
1513
+ timestamp seconds to a float, since it occasionally results in inaccuracies
1514
+ with microsecond-precision times. Fixes #7352.
1515
+
1516
+ *Ari Pollak*
1517
+
1518
+ * Fix AR#dup to nullify the validation errors in the dup'ed object. Previously the original
1519
+ and the dup'ed object shared the same errors.
1520
+
1521
+ *Christian Seiler*
1522
+
1523
+ * Raise `ArgumentError` if list of attributes to change is empty in `update_all`.
1524
+
1525
+ *Roman Shatsov*
1526
+
1527
+ * Fix AR#create to return an unsaved record when AR::RecordInvalid is
1528
+ raised. Fixes #3217.
1529
+
1530
+ *Dave Yeu*
1531
+
1532
+ * Fixed table name prefix that is generated in engines for namespaced models.
1533
+
1534
+ *Wojciech Wnętrzak*
1535
+
1536
+ * Make sure `:environment` task is executed before `db:schema:load` or `db:structure:load`.
1537
+ Fixes #4772.
1538
+
1539
+ *Seamus Abshere*
1540
+
1541
+ * Allow Relation#merge to take a proc.
1542
+
1543
+ This was requested by DHH to allow creating of one's own custom
1544
+ association macros.
1545
+
1546
+ For example:
1547
+
1548
+ module Commentable
1549
+ def has_many_comments(extra)
1550
+ has_many :comments, -> { where(:foo).merge(extra) }
1551
+ end
1552
+ end
1553
+
1554
+ class Post < ActiveRecord::Base
1555
+ extend Commentable
1556
+ has_many_comments -> { where(:bar) }
1557
+ end
1558
+
1559
+ *Jon Leighton*
1560
+
1561
+ * Add CollectionProxy#scope.
1562
+
1563
+ This can be used to get a Relation from an association.
1564
+
1565
+ Previously we had a #scoped method, but we're deprecating that for
1566
+ AR::Base, so it doesn't make sense to have it here.
1567
+
1568
+ This was requested by DHH, to facilitate code like this:
1569
+
1570
+ Project.scope.order('created_at DESC').page(current_page).tagged_with(@tag).limit(5).scoping do
1571
+ @topics = @project.topics.scope
1572
+ @todolists = @project.todolists.scope
1573
+ @attachments = @project.attachments.scope
1574
+ @documents = @project.documents.scope
1575
+ end
1576
+
1577
+ *Jon Leighton*
1578
+
1579
+ * Add `Relation#load`.
1580
+
1581
+ This method explicitly loads the records and then returns `self`.
1582
+
1583
+ Rather than deciding between "do I want an array or a relation?",
1584
+ most people are actually asking themselves "do I want to eager load
1585
+ or lazy load?" Therefore, this method provides a way to explicitly
1586
+ eager-load without having to switch from a `Relation` to an array.
1587
+
1588
+ Example:
1589
+
1590
+ @posts = Post.where(published: true).load
1591
+
1592
+ *Jon Leighton*
1593
+
1594
+ * `Relation#order`: make new order prepend old one.
1595
+
1596
+ User.order("name asc").order("created_at desc")
1597
+ # SELECT * FROM users ORDER BY created_at desc, name asc
1598
+
1599
+ This also affects order defined in `default_scope` or any kind of associations.
1600
+
1601
+ *Bogdan Gusiev*
1602
+
1603
+ * `Model.all` now returns an `ActiveRecord::Relation`, rather than an
1604
+ array of records. Use `Relation#to_a` if you really want an array.
1605
+
1606
+ In some specific cases, this may cause breakage when upgrading.
1607
+ However in most cases the `ActiveRecord::Relation` will just act as a
1608
+ lazy-loaded array and there will be no problems.
1609
+
1610
+ Note that calling `Model.all` with options (e.g.
1611
+ `Model.all(conditions: '...')` was already deprecated, but it will
1612
+ still return an array in order to make the transition easier.
1613
+
1614
+ `Model.scoped` is deprecated in favour of `Model.all`.
1615
+
1616
+ `Relation#all` still returns an array, but is deprecated (since it
1617
+ would serve no purpose if we made it return a `Relation`).
1618
+
1619
+ *Jon Leighton*
1620
+
1621
+ * `:finder_sql` and `:counter_sql` options on collection associations
1622
+ are deprecated. Please transition to using scopes.
1623
+
1624
+ *Jon Leighton*
1625
+
1626
+ * `:insert_sql` and `:delete_sql` options on `has_and_belongs_to_many`
1627
+ associations are deprecated. Please transition to using `has_many
1628
+ :through`.
1629
+
1630
+ *Jon Leighton*
1631
+
1632
+ * Added `#update_columns` method which updates the attributes from
1633
+ the passed-in hash without calling save, hence skipping validations and
1634
+ callbacks. `ActiveRecordError` will be raised when called on new objects
1635
+ or when at least one of the attributes is marked as read only.
1636
+
1637
+ post.attributes # => {"id"=>2, "title"=>"My title", "body"=>"My content", "author"=>"Peter"}
1638
+ post.update_columns(title: 'New title', author: 'Sebastian') # => true
1639
+ post.attributes # => {"id"=>2, "title"=>"New title", "body"=>"My content", "author"=>"Sebastian"}
1640
+
1641
+ *Sebastian Martinez + Rafael Mendonça França*
1642
+
1643
+ * The migration generator now creates a join table with (commented) indexes every time
1644
+ the migration name contains the word `join_table`:
1645
+
1646
+ rails g migration create_join_table_for_artists_and_musics artist_id:index music_id
1647
+
1648
+ *Aleksey Magusev*
1649
+
1650
+ * Add `add_reference` and `remove_reference` schema statements. Aliases, `add_belongs_to`
1651
+ and `remove_belongs_to` are acceptable. References are reversible.
1652
+
1653
+ Examples:
1654
+
1655
+ # Create a user_id column
1656
+ add_reference(:products, :user)
1657
+ # Create a supplier_id, supplier_type columns and appropriate index
1658
+ add_reference(:products, :supplier, polymorphic: true, index: true)
1659
+ # Remove polymorphic reference
1660
+ remove_reference(:products, :supplier, polymorphic: true)
1661
+
1662
+ *Aleksey Magusev*
1663
+
1664
+ * Add `:default` and `:null` options to `column_exists?`.
1665
+
1666
+ column_exists?(:testings, :taggable_id, :integer, null: false)
1667
+ column_exists?(:testings, :taggable_type, :string, default: 'Photo')
1668
+
1669
+ *Aleksey Magusev*
1670
+
1671
+ * `ActiveRecord::Relation#inspect` now makes it clear that you are
1672
+ dealing with a `Relation` object rather than an array:.
1673
+
1674
+ User.where(age: 30).inspect
1675
+ # => <ActiveRecord::Relation [#<User ...>, #<User ...>, ...]>
1676
+
1677
+ User.where(age: 30).to_a.inspect
1678
+ # => [#<User ...>, #<User ...>]
1679
+
1680
+ The number of records displayed will be limited to 10.
1681
+
1682
+ *Brian Cardarella, Jon Leighton & Damien Mathieu*
1683
+
1684
+ * Add `collation` and `ctype` support to PostgreSQL. These are available for PostgreSQL 8.4 or later.
1685
+ Example:
1686
+
1687
+ development:
1688
+ adapter: postgresql
1689
+ host: localhost
1690
+ database: rails_development
1691
+ username: foo
1692
+ password: bar
1693
+ encoding: UTF8
1694
+ collation: ja_JP.UTF8
1695
+ ctype: ja_JP.UTF8
1696
+
1697
+ *kennyj*
1698
+
1699
+ * Changed `validates_presence_of` on an association so that children objects
1700
+ do not validate as being present if they are marked for destruction. This
1701
+ prevents you from saving the parent successfully and thus putting the parent
1702
+ in an invalid state.
1703
+
1704
+ *Nick Monje & Brent Wheeldon*
1705
+
1706
+ * `FinderMethods#exists?` now returns `false` with the `false` argument.
1707
+
1708
+ *Egor Lynko*
1709
+
1710
+ * Added support for specifying the precision of a timestamp in the PostgreSQL
1711
+ adapter. So, instead of having to incorrectly specify the precision using the
1712
+ `:limit` option, you may use `:precision`, as intended. For example, in a migration:
1713
+
1714
+ def change
1715
+ create_table :foobars do |t|
1716
+ t.timestamps precision: 0
1717
+ end
1718
+ end
1719
+
1720
+ *Tony Schneider*
1721
+
1722
+ * Allow `ActiveRecord::Relation#pluck` to accept multiple columns. Returns an
1723
+ array of arrays containing the typecasted values:
1724
+
1725
+ Person.pluck(:id, :name)
1726
+ # SELECT people.id, people.name FROM people
1727
+ # [[1, 'David'], [2, 'Jeremy'], [3, 'Jose']]
1728
+
1729
+ *Jeroen van Ingen & Carlos Antonio da Silva*
1730
+
1731
+ * Improve the derivation of HABTM join table name to take account of nesting.
1732
+ It now takes the table names of the two models, sorts them lexically and
1733
+ then joins them, stripping any common prefix from the second table name.
1734
+
1735
+ Some examples:
1736
+
1737
+ Top level models (Category <=> Product)
1738
+ Old: categories_products
1739
+ New: categories_products
1740
+
1741
+ Top level models with a global table_name_prefix (Category <=> Product)
1742
+ Old: site_categories_products
1743
+ New: site_categories_products
1744
+
1745
+ Nested models in a module without a table_name_prefix method (Admin::Category <=> Admin::Product)
1746
+ Old: categories_products
1747
+ New: categories_products
1748
+
1749
+ Nested models in a module with a table_name_prefix method (Admin::Category <=> Admin::Product)
1750
+ Old: categories_products
1751
+ New: admin_categories_products
1752
+
1753
+ Nested models in a parent model (Catalog::Category <=> Catalog::Product)
1754
+ Old: categories_products
1755
+ New: catalog_categories_products
1756
+
1757
+ Nested models in different parent models (Catalog::Category <=> Content::Page)
1758
+ Old: categories_pages
1759
+ New: catalog_categories_content_pages
1760
+
1761
+ *Andrew White*
1762
+
1763
+ * Move HABTM validity checks to `ActiveRecord::Reflection`. One side effect of
1764
+ this is to move when the exceptions are raised from the point of declaration
1765
+ to when the association is built. This is consistent with other association
1766
+ validity checks.
1767
+
1768
+ *Andrew White*
1769
+
1770
+ * Added `stored_attributes` hash which contains the attributes stored using
1771
+ `ActiveRecord::Store`. This allows you to retrieve the list of attributes
1772
+ you've defined.
1773
+
1774
+ class User < ActiveRecord::Base
1775
+ store :settings, accessors: [:color, :homepage]
1776
+ end
1777
+
1778
+ User.stored_attributes[:settings] # [:color, :homepage]
1779
+
1780
+ *Joost Baaij & Carlos Antonio da Silva*
1781
+
1782
+ * PostgreSQL default log level is now 'warning', to bypass the noisy notice
1783
+ messages. You can change the log level using the `min_messages` option
1784
+ available in your config/database.yml.
1785
+
1786
+ *kennyj*
1787
+
1788
+ * Add uuid datatype support to PostgreSQL adapter.
1789
+
1790
+ *Konstantin Shabanov*
1791
+
1792
+ * Added `ActiveRecord::Migration.check_pending!` that raises an error if
1793
+ migrations are pending.
1794
+
1795
+ *Richard Schneeman*
1796
+
1797
+ * Added `#destroy!` which acts like `#destroy` but will raise an
1798
+ `ActiveRecord::RecordNotDestroyed` exception instead of returning `false`.
1799
+
1800
+ *Marc-André Lafortune*
1801
+
1802
+ * Added support to `CollectionAssociation#delete` for passing `fixnum`
1803
+ or `string` values as record ids. This finds the records responding
1804
+ to the `id` and executes delete on them.
1805
+
1806
+ class Person < ActiveRecord::Base
1807
+ has_many :pets
1808
+ end
1809
+
1810
+ person.pets.delete("1") # => [#<Pet id: 1>]
1811
+ person.pets.delete(2, 3) # => [#<Pet id: 2>, #<Pet id: 3>]
1812
+
1813
+ *Francesco Rodriguez*
1814
+
1815
+ * Deprecated most of the 'dynamic finder' methods. All dynamic methods
1816
+ except for `find_by_...` and `find_by_...!` are deprecated. Here's
1817
+ how you can rewrite the code:
1818
+
1819
+ * `find_all_by_...` can be rewritten using `where(...)`
1820
+ * `find_last_by_...` can be rewritten using `where(...).last`
1821
+ * `scoped_by_...` can be rewritten using `where(...)`
1822
+ * `find_or_initialize_by_...` can be rewritten using
1823
+ `where(...).first_or_initialize`
1824
+ * `find_or_create_by_...` can be rewritten using
1825
+ `find_or_create_by(...)` or where(...).first_or_create`
1826
+ * `find_or_create_by_...!` can be rewritten using
1827
+ `find_or_create_by!(...) or `where(...).first_or_create!`
1828
+
1829
+ The implementation of the deprecated dynamic finders has been moved
1830
+ to the `activerecord-deprecated_finders` gem. See below for details.
1831
+
1832
+ *Jon Leighton*
1833
+
1834
+ * Deprecated the old-style hash based finder API. This means that
1835
+ methods which previously accepted "finder options" no longer do. For
1836
+ example this:
1837
+
1838
+ Post.find(:all, conditions: { comments_count: 10 }, limit: 5)
1839
+
1840
+ Should be rewritten in the new style which has existed since Rails 3:
1841
+
1842
+ Post.where(comments_count: 10).limit(5)
1843
+
1844
+ Note that as an interim step, it is possible to rewrite the above as:
1845
+
1846
+ Post.all.merge(where: { comments_count: 10 }, limit: 5)
1847
+
1848
+ This could save you a lot of work if there is a lot of old-style
1849
+ finder usage in your application.
1850
+
1851
+ `Relation#merge` now accepts a hash of
1852
+ options, but they must be identical to the names of the equivalent
1853
+ finder method. These are mostly identical to the old-style finder
1854
+ option names, except in the following cases:
1855
+
1856
+ * `:conditions` becomes `:where`.
1857
+ * `:include` becomes `:includes`.
1858
+
1859
+ The code to implement the deprecated features has been moved out to the
1860
+ `activerecord-deprecated_finders` gem. This gem is a dependency of Active
1861
+ Record in Rails 4.0, so the interface works out of the box. It will no
1862
+ longer be a dependency from Rails 4.1 (you'll need to add it to the
1863
+ `Gemfile` in 4.1), and will be maintained until Rails 5.0.
1864
+
1865
+ *Jon Leighton*
1866
+
1867
+ * It's not possible anymore to destroy a model marked as read only.
1868
+
1869
+ *Johannes Barre*
1870
+
1871
+ * Added ability to ActiveRecord::Relation#from to accept other ActiveRecord::Relation objects.
1872
+
1873
+ Record.from(subquery)
1874
+ Record.from(subquery, :a)
1875
+
1876
+ *Radoslav Stankov*
1877
+
1878
+ * Added custom coders support for ActiveRecord::Store. Now you can set
1879
+ your custom coder like this:
1880
+
1881
+ store :settings, accessors: [ :color, :homepage ], coder: JSON
1882
+
1883
+ *Andrey Voronkov*
1884
+
1885
+ * `mysql` and `mysql2` connections will set `SQL_MODE=STRICT_ALL_TABLES` by
1886
+ default to avoid silent data loss. This can be disabled by specifying
1887
+ `strict: false` in your `database.yml`.
1888
+
1889
+ *Michael Pearson*
1890
+
1891
+ * Added default order to `first` to assure consistent results among
1892
+ different database engines. Introduced `take` as a replacement to
1893
+ the old behavior of `first`.
1894
+
1895
+ *Marcelo Silveira*
1896
+
1897
+ * Added an `:index` option to automatically create indexes for references
1898
+ and belongs_to statements in migrations.
1899
+
1900
+ The `references` and `belongs_to` methods now support an `index`
1901
+ option that receives either a boolean value or an options hash
1902
+ that is identical to options available to the add_index method:
1903
+
1904
+ create_table :messages do |t|
1905
+ t.references :person, index: true
1906
+ end
1907
+
1908
+ Is the same as:
1909
+
1910
+ create_table :messages do |t|
1911
+ t.references :person
1912
+ end
1913
+ add_index :messages, :person_id
1914
+
1915
+ Generators have also been updated to use the new syntax.
1916
+
1917
+ *Joshua Wood*
1918
+
1919
+ * Added `#find_by` and `#find_by!` to mirror the functionality
1920
+ provided by dynamic finders in a way that allows dynamic input more
1921
+ easily:
1922
+
1923
+ Post.find_by name: 'Spartacus', rating: 4
1924
+ Post.find_by "published_at < ?", 2.weeks.ago
1925
+ Post.find_by! name: 'Spartacus'
1926
+
1927
+ *Jon Leighton*
1928
+
1929
+ * Added ActiveRecord::Base#slice to return a hash of the given methods with
1930
+ their names as keys and returned values as values.
1931
+
1932
+ *Guillermo Iguaran*
1933
+
1934
+ * Deprecate eager-evaluated scopes.
1935
+
1936
+ Don't use this:
1937
+
1938
+ scope :red, where(color: 'red')
1939
+ default_scope where(color: 'red')
1940
+
1941
+ Use this:
1942
+
1943
+ scope :red, -> { where(color: 'red') }
1944
+ default_scope { where(color: 'red') }
1945
+
1946
+ The former has numerous issues. It is a common newbie gotcha to do
1947
+ the following:
1948
+
1949
+ scope :recent, where(published_at: Time.now - 2.weeks)
1950
+
1951
+ Or a more subtle variant:
1952
+
1953
+ scope :recent, -> { where(published_at: Time.now - 2.weeks) }
1954
+ scope :recent_red, recent.where(color: 'red')
1955
+
1956
+ Eager scopes are also very complex to implement within Active
1957
+ Record, and there are still bugs. For example, the following does
1958
+ not do what you expect:
1959
+
1960
+ scope :remove_conditions, except(:where)
1961
+ where(...).remove_conditions # => still has conditions
1962
+
1963
+ *Jon Leighton*
1964
+
1965
+ * Remove IdentityMap
1966
+
1967
+ IdentityMap has never graduated to be an "enabled-by-default" feature, due
1968
+ to some inconsistencies with associations, as described in this commit:
1969
+
1970
+ https://github.com/rails/rails/commit/302c912bf6bcd0fa200d964ec2dc4a44abe328a6
1971
+
1972
+ Hence the removal from the codebase, until such issues are fixed.
1973
+
1974
+ *Carlos Antonio da Silva*
1975
+
1976
+ * Added the schema cache dump feature.
1977
+
1978
+ `Schema cache dump` feature was implemented. This feature can dump/load internal state of `SchemaCache` instance
1979
+ because we want to boot rails more quickly when we have many models.
1980
+
1981
+ Usage notes:
1982
+
1983
+ 1) execute rake task.
1984
+ RAILS_ENV=production bundle exec rake db:schema:cache:dump
1985
+ => generate db/schema_cache.dump
1986
+
1987
+ 2) add config.active_record.use_schema_cache_dump = true in config/production.rb. BTW, true is default.
1988
+
1989
+ 3) boot rails.
1990
+ RAILS_ENV=production bundle exec rails server
1991
+ => use db/schema_cache.dump
1992
+
1993
+ 4) If you remove clear dumped cache, execute rake task.
1994
+ RAILS_ENV=production bundle exec rake db:schema:cache:clear
1995
+ => remove db/schema_cache.dump
1996
+
1997
+ *kennyj*
1998
+
1999
+ * Added support for partial indices to PostgreSQL adapter.
2000
+
2001
+ The `add_index` method now supports a `where` option that receives a
2002
+ string with the partial index criteria.
2003
+
2004
+ add_index(:accounts, :code, where: 'active')
2005
+
2006
+ generates
2007
+
2008
+ CREATE INDEX index_accounts_on_code ON accounts(code) WHERE active
2009
+
2010
+ *Marcelo Silveira*
2011
+
2012
+ * Implemented `ActiveRecord::Relation#none` method.
2013
+
2014
+ The `none` method returns a chainable relation with zero records
2015
+ (an instance of the NullRelation class).
2016
+
2017
+ Any subsequent condition chained to the returned relation will continue
2018
+ generating an empty relation and will not fire any query to the database.
2019
+
2020
+ *Juanjo Bazán*
2021
+
2022
+ * Added the `ActiveRecord::NullRelation` class implementing the null
2023
+ object pattern for the Relation class.
2024
+
2025
+ *Juanjo Bazán*
2026
+
2027
+ * Added new `dependent: :restrict_with_error` option. This will add
2028
+ an error to the model, rather than raising an exception.
2029
+
2030
+ The `:restrict` option is renamed to `:restrict_with_exception` to
2031
+ make this distinction explicit.
2032
+
2033
+ *Manoj Kumar & Jon Leighton*
2034
+
2035
+ * Added `create_join_table` migration helper to create HABTM join tables.
2036
+
2037
+ create_join_table :products, :categories
2038
+ # =>
2039
+ # create_table :categories_products, id: false do |td|
2040
+ # td.integer :product_id, null: false
2041
+ # td.integer :category_id, null: false
2042
+ # end
2043
+
2044
+ *Rafael Mendonça França*
2045
+
2046
+ * The primary key is always initialized in the @attributes hash to `nil` (unless
2047
+ another value has been specified).
2048
+
2049
+ *Aaron Paterson*
2050
+
2051
+ * In previous releases, the following would generate a single query with
2052
+ an `OUTER JOIN comments`, rather than two separate queries:
2053
+
2054
+ Post.includes(:comments)
2055
+ .where("comments.name = 'foo'")
2056
+
2057
+ This behaviour relies on matching SQL string, which is an inherently
2058
+ flawed idea unless we write an SQL parser, which we do not wish to
2059
+ do.
2060
+
2061
+ Therefore, it is now deprecated.
2062
+
2063
+ To avoid deprecation warnings and for future compatibility, you must
2064
+ explicitly state which tables you reference, when using SQL snippets:
2065
+
2066
+ Post.includes(:comments)
2067
+ .where("comments.name = 'foo'")
2068
+ .references(:comments)
2069
+
2070
+ Note that you do not need to explicitly specify references in the
2071
+ following cases, as they can be automatically inferred:
2072
+
2073
+ Post.includes(:comments).where(comments: { name: 'foo' })
2074
+ Post.includes(:comments).where('comments.name' => 'foo')
2075
+ Post.includes(:comments).order('comments.name')
2076
+
2077
+ You do not need to worry about this unless you are doing eager
2078
+ loading. Basically, don't worry unless you see a deprecation warning
2079
+ or (in future releases) an SQL error due to a missing JOIN.
2080
+
2081
+ *Jon Leighton*
2082
+
2083
+ * Support for the `schema_info` table has been dropped. Please
2084
+ switch to `schema_migrations`.
2085
+
2086
+ *Aaron Patterson*
2087
+
2088
+ * Connections *must* be closed at the end of a thread. If not, your
2089
+ connection pool can fill and an exception will be raised.
2090
+
2091
+ *Aaron Patterson*
2092
+
2093
+ * PostgreSQL hstore records can be created.
2094
+
2095
+ *Aaron Patterson*
2096
+
2097
+ * PostgreSQL hstore types are automatically deserialized from the database.
2098
+
2099
+ *Aaron Patterson*
2100
+
2101
+
2102
+ Please check [3-2-stable](https://github.com/rails/rails/blob/3-2-stable/activerecord/CHANGELOG.md) for previous changes.