activerecord 3.2.22.5 → 4.0.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 (162) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1024 -543
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +20 -29
  5. data/examples/performance.rb +1 -1
  6. data/lib/active_record.rb +55 -44
  7. data/lib/active_record/aggregations.rb +40 -34
  8. data/lib/active_record/associations.rb +204 -276
  9. data/lib/active_record/associations/alias_tracker.rb +1 -1
  10. data/lib/active_record/associations/association.rb +30 -35
  11. data/lib/active_record/associations/association_scope.rb +40 -40
  12. data/lib/active_record/associations/belongs_to_association.rb +15 -2
  13. data/lib/active_record/associations/builder/association.rb +81 -28
  14. data/lib/active_record/associations/builder/belongs_to.rb +35 -57
  15. data/lib/active_record/associations/builder/collection_association.rb +54 -40
  16. data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +23 -41
  17. data/lib/active_record/associations/builder/has_many.rb +8 -64
  18. data/lib/active_record/associations/builder/has_one.rb +13 -50
  19. data/lib/active_record/associations/builder/singular_association.rb +13 -13
  20. data/lib/active_record/associations/collection_association.rb +92 -88
  21. data/lib/active_record/associations/collection_proxy.rb +913 -63
  22. data/lib/active_record/associations/has_and_belongs_to_many_association.rb +12 -10
  23. data/lib/active_record/associations/has_many_association.rb +35 -9
  24. data/lib/active_record/associations/has_many_through_association.rb +24 -14
  25. data/lib/active_record/associations/has_one_association.rb +33 -13
  26. data/lib/active_record/associations/has_one_through_association.rb +1 -1
  27. data/lib/active_record/associations/join_dependency.rb +2 -2
  28. data/lib/active_record/associations/join_dependency/join_association.rb +17 -22
  29. data/lib/active_record/associations/join_dependency/join_part.rb +1 -1
  30. data/lib/active_record/associations/join_helper.rb +1 -11
  31. data/lib/active_record/associations/preloader.rb +14 -17
  32. data/lib/active_record/associations/preloader/association.rb +29 -33
  33. data/lib/active_record/associations/preloader/collection_association.rb +1 -1
  34. data/lib/active_record/associations/preloader/has_and_belongs_to_many.rb +1 -1
  35. data/lib/active_record/associations/preloader/has_many_through.rb +1 -1
  36. data/lib/active_record/associations/preloader/has_one.rb +1 -1
  37. data/lib/active_record/associations/preloader/through_association.rb +13 -17
  38. data/lib/active_record/associations/singular_association.rb +11 -11
  39. data/lib/active_record/associations/through_association.rb +2 -2
  40. data/lib/active_record/attribute_assignment.rb +133 -153
  41. data/lib/active_record/attribute_methods.rb +196 -93
  42. data/lib/active_record/attribute_methods/before_type_cast.rb +44 -5
  43. data/lib/active_record/attribute_methods/dirty.rb +31 -28
  44. data/lib/active_record/attribute_methods/primary_key.rb +38 -30
  45. data/lib/active_record/attribute_methods/query.rb +5 -4
  46. data/lib/active_record/attribute_methods/read.rb +62 -91
  47. data/lib/active_record/attribute_methods/serialization.rb +97 -66
  48. data/lib/active_record/attribute_methods/time_zone_conversion.rb +39 -45
  49. data/lib/active_record/attribute_methods/write.rb +32 -39
  50. data/lib/active_record/autosave_association.rb +56 -70
  51. data/lib/active_record/base.rb +53 -450
  52. data/lib/active_record/callbacks.rb +53 -18
  53. data/lib/active_record/coders/yaml_column.rb +11 -9
  54. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +353 -197
  55. data/lib/active_record/connection_adapters/abstract/database_limits.rb +9 -0
  56. data/lib/active_record/connection_adapters/abstract/database_statements.rb +130 -131
  57. data/lib/active_record/connection_adapters/abstract/query_cache.rb +24 -19
  58. data/lib/active_record/connection_adapters/abstract/quoting.rb +23 -3
  59. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +101 -91
  60. data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +59 -0
  61. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +225 -96
  62. data/lib/active_record/connection_adapters/abstract/transaction.rb +203 -0
  63. data/lib/active_record/connection_adapters/abstract_adapter.rb +99 -46
  64. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +114 -36
  65. data/lib/active_record/connection_adapters/column.rb +46 -24
  66. data/lib/active_record/connection_adapters/connection_specification.rb +96 -0
  67. data/lib/active_record/connection_adapters/mysql2_adapter.rb +16 -32
  68. data/lib/active_record/connection_adapters/mysql_adapter.rb +181 -64
  69. data/lib/active_record/connection_adapters/postgresql/array_parser.rb +97 -0
  70. data/lib/active_record/connection_adapters/postgresql/cast.rb +132 -0
  71. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +242 -0
  72. data/lib/active_record/connection_adapters/postgresql/oid.rb +347 -0
  73. data/lib/active_record/connection_adapters/postgresql/quoting.rb +158 -0
  74. data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +30 -0
  75. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +448 -0
  76. data/lib/active_record/connection_adapters/postgresql_adapter.rb +454 -885
  77. data/lib/active_record/connection_adapters/schema_cache.rb +48 -16
  78. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +574 -13
  79. data/lib/active_record/connection_handling.rb +98 -0
  80. data/lib/active_record/core.rb +428 -0
  81. data/lib/active_record/counter_cache.rb +106 -108
  82. data/lib/active_record/dynamic_matchers.rb +110 -63
  83. data/lib/active_record/errors.rb +25 -8
  84. data/lib/active_record/explain.rb +8 -58
  85. data/lib/active_record/explain_subscriber.rb +6 -3
  86. data/lib/active_record/fixture_set/file.rb +56 -0
  87. data/lib/active_record/fixtures.rb +146 -148
  88. data/lib/active_record/inheritance.rb +77 -59
  89. data/lib/active_record/integration.rb +5 -5
  90. data/lib/active_record/locale/en.yml +8 -1
  91. data/lib/active_record/locking/optimistic.rb +38 -42
  92. data/lib/active_record/locking/pessimistic.rb +4 -4
  93. data/lib/active_record/log_subscriber.rb +19 -9
  94. data/lib/active_record/migration.rb +318 -153
  95. data/lib/active_record/migration/command_recorder.rb +90 -31
  96. data/lib/active_record/migration/join_table.rb +15 -0
  97. data/lib/active_record/model_schema.rb +69 -92
  98. data/lib/active_record/nested_attributes.rb +113 -148
  99. data/lib/active_record/null_relation.rb +65 -0
  100. data/lib/active_record/persistence.rb +188 -97
  101. data/lib/active_record/query_cache.rb +18 -36
  102. data/lib/active_record/querying.rb +19 -15
  103. data/lib/active_record/railtie.rb +91 -36
  104. data/lib/active_record/railties/console_sandbox.rb +0 -2
  105. data/lib/active_record/railties/controller_runtime.rb +2 -2
  106. data/lib/active_record/railties/databases.rake +90 -309
  107. data/lib/active_record/railties/jdbcmysql_error.rb +1 -1
  108. data/lib/active_record/readonly_attributes.rb +7 -3
  109. data/lib/active_record/reflection.rb +72 -56
  110. data/lib/active_record/relation.rb +241 -157
  111. data/lib/active_record/relation/batches.rb +25 -22
  112. data/lib/active_record/relation/calculations.rb +143 -121
  113. data/lib/active_record/relation/delegation.rb +96 -18
  114. data/lib/active_record/relation/finder_methods.rb +117 -183
  115. data/lib/active_record/relation/merger.rb +133 -0
  116. data/lib/active_record/relation/predicate_builder.rb +90 -42
  117. data/lib/active_record/relation/query_methods.rb +666 -136
  118. data/lib/active_record/relation/spawn_methods.rb +43 -150
  119. data/lib/active_record/result.rb +33 -6
  120. data/lib/active_record/sanitization.rb +24 -50
  121. data/lib/active_record/schema.rb +19 -12
  122. data/lib/active_record/schema_dumper.rb +31 -39
  123. data/lib/active_record/schema_migration.rb +36 -0
  124. data/lib/active_record/scoping.rb +0 -124
  125. data/lib/active_record/scoping/default.rb +48 -45
  126. data/lib/active_record/scoping/named.rb +74 -103
  127. data/lib/active_record/serialization.rb +6 -2
  128. data/lib/active_record/serializers/xml_serializer.rb +9 -15
  129. data/lib/active_record/store.rb +119 -15
  130. data/lib/active_record/tasks/database_tasks.rb +158 -0
  131. data/lib/active_record/tasks/mysql_database_tasks.rb +138 -0
  132. data/lib/active_record/tasks/postgresql_database_tasks.rb +90 -0
  133. data/lib/active_record/tasks/sqlite_database_tasks.rb +51 -0
  134. data/lib/active_record/test_case.rb +61 -38
  135. data/lib/active_record/timestamp.rb +8 -9
  136. data/lib/active_record/transactions.rb +65 -51
  137. data/lib/active_record/validations.rb +17 -15
  138. data/lib/active_record/validations/associated.rb +20 -14
  139. data/lib/active_record/validations/presence.rb +65 -0
  140. data/lib/active_record/validations/uniqueness.rb +93 -52
  141. data/lib/active_record/version.rb +4 -4
  142. data/lib/rails/generators/active_record.rb +3 -5
  143. data/lib/rails/generators/active_record/migration/migration_generator.rb +37 -7
  144. data/lib/rails/generators/active_record/migration/templates/migration.rb +20 -15
  145. data/lib/rails/generators/active_record/model/model_generator.rb +4 -3
  146. data/lib/rails/generators/active_record/model/templates/model.rb +1 -6
  147. data/lib/rails/generators/active_record/model/templates/module.rb +1 -1
  148. metadata +53 -46
  149. data/lib/active_record/attribute_methods/deprecated_underscore_read.rb +0 -32
  150. data/lib/active_record/connection_adapters/abstract/connection_specification.rb +0 -191
  151. data/lib/active_record/connection_adapters/sqlite_adapter.rb +0 -583
  152. data/lib/active_record/dynamic_finder_match.rb +0 -68
  153. data/lib/active_record/dynamic_scope_match.rb +0 -23
  154. data/lib/active_record/fixtures/file.rb +0 -65
  155. data/lib/active_record/identity_map.rb +0 -162
  156. data/lib/active_record/observer.rb +0 -121
  157. data/lib/active_record/session_store.rb +0 -360
  158. data/lib/rails/generators/active_record/migration.rb +0 -15
  159. data/lib/rails/generators/active_record/observer/observer_generator.rb +0 -15
  160. data/lib/rails/generators/active_record/observer/templates/observer.rb +0 -4
  161. data/lib/rails/generators/active_record/session_migration/session_migration_generator.rb +0 -25
  162. data/lib/rails/generators/active_record/session_migration/templates/migration.rb +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b2a1b133cbd413ee58ccc671828333632ed6db3b
4
- data.tar.gz: 8f7eed84647eebadf1270dc241dca3063b4586f5
3
+ metadata.gz: 8b06fdbc87492769dd5d79108a95f66047b330b0
4
+ data.tar.gz: 2695993c7be8d8a4d56f88eb0ba19fc844e86b54
5
5
  SHA512:
6
- metadata.gz: 0bef1cca318f136e3c84fda17c030b840b6d889a836dee9753b000bde1fa951b90873145d6a79f7f42d76db8ae6fa66e79244baea47f5e440f8dafa1ecd6325e
7
- data.tar.gz: 98f44f3efcaa299b5044a14851dc577b63c6281d4f18c152ce2fd4de1562170e8fa6aac3109eb101fdc1b5df05f5cb06efc1b8ea6ab7e69e080ebbac137a74fd
6
+ metadata.gz: f0c5bbb50b6b28e0208a50bea7f4268f3d9bc1de8353c2ddb5219675324fb2dbd9fe6ff2e0f662d161cd06f6532a87a51a7a1a70bdbad52bc03af438fa79cfa6
7
+ data.tar.gz: 32eecd85c4382a9b6e64b9c6b26354bc9fbffd974d65681e74f709d789dcf0474bb4bda94f52a1c4d538e2af17c70db2667126e36ceeb6f4c87e56e57a1195a6
@@ -1,260 +1,227 @@
1
- * Support Ruby 2.3 by not unexpectedly calling `.to_proc` on Hash objects
1
+ ## Rails 4.0.0.beta1 (February 25, 2013) ##
2
2
 
3
- Fixes #25010
3
+ * Fix overriding of attributes by default_scope on `ActiveRecord::Base#dup`.
4
4
 
5
- *tlrdstd*
6
-
7
- ## Rails 3.2.22 (Jun 16, 2015) ##
8
-
9
- * No changes.
10
-
11
-
12
- ## Rails 3.2.19 (Jul 2, 2014) ##
13
-
14
- * Fix SQL Injection Vulnerability in 'bitstring' quoting.
15
-
16
- Fixes CVE-2014-3482.
17
-
18
- *Rafael Mendonça França*
19
-
20
-
21
- ## Rails 3.2.18 (May 6, 2014) ##
22
-
23
- * No changes.
24
-
25
-
26
- ## Rails 3.2.17 (Feb 18, 2014) ##
27
-
28
- * No changes.
29
-
30
-
31
- ## Rails 3.2.16 (Dec 3, 2013) ##
32
-
33
- * No changes.
34
-
35
-
36
- ## Rails 3.2.15 (Oct 16, 2013) ##
37
-
38
- * When calling the method .find_or_initialize_by_* from a collection_proxy
39
- it should set the inverse_of relation even when the entry was found on the db.
40
-
41
- *arthurnn*
42
-
43
- * Callbacks on has_many should access the in memory parent if a inverse_of is set.
44
-
45
- *arthurnn*
46
-
47
- * Fix `FinderMethods#last` unscoped primary key.
48
-
49
- Fixes #11917.
50
-
51
- *Eugene Kalenkovich*
52
-
53
- * Load fixtures from linked folders.
54
-
55
- *Kassio Borges*
56
-
57
- * When using optimistic locking, `update` was not passing the column to `quote_value`
58
- to allow the connection adapter to properly determine how to quote the value. This was
59
- affecting certain databases that use specific colmn types.
5
+ *Hiroshige UMINO*
60
6
 
61
- Fixes: #6763
7
+ * Fixing issue #8345. Now throwing an error when one attempts to touch a
8
+ new object that has not yet been persisted. For instance:
62
9
 
63
- *Alfred Wong*
10
+ Example:
64
11
 
12
+ ball = Ball.new
13
+ ball.touch :updated_at # => raises error
65
14
 
66
- ## Rails 3.2.14 (Jul 22, 2013) ##
15
+ It is not until the ball object has been persisted that it can be touched.
16
+ This follows the behavior of update_column.
67
17
 
68
- * Fix merge error when Equality LHS is non-attribute.
69
- Backport of #7380.
18
+ *John Wang*
70
19
 
71
- *Karmes Alexander*
20
+ * Preloading ordered `has_many :through` associations no longer applies
21
+ invalid ordering to the `:through` association.
22
+ Fixes #8663.
72
23
 
73
- * Do not re-create destroyed association when saving the parent object.
24
+ *Yves Senn*
74
25
 
75
- Fixes #11450.
26
+ * The auto explain feature has been removed. This feature was
27
+ activated by configuring `config.active_record.auto_explain_threshold_in_seconds`.
28
+ The configuration option was deprecated and has no more effect.
76
29
 
77
- *Paul Nikitochkin*
30
+ You can still use `ActiveRecord::Relation#explain` to see the EXPLAIN output for
31
+ any given relation.
78
32
 
79
- * Do not shallow the original exception in `exec_cache` on PostgreSQL adapter.
33
+ *Yves Senn*
80
34
 
81
- Fixes #11260.
35
+ * The `:on` option for `after_commit` and `after_rollback` now
36
+ accepts an Array of actions.
37
+ Fixes #988.
82
38
 
83
- *Rafael Mendonça França*
39
+ Example:
84
40
 
85
- * Fix `ActiveRecord::Store` incorrectly tracking changes of its attributes.
86
- Fixes #10373.
41
+ after_commit :update_cache on: [:create, :update]
87
42
 
88
- *Janko Marohnić*
43
+ *Yves Senn*
89
44
 
90
- * Fix a bug that prevented the use of the default STI inheritance column
91
- (ActiveRecord::Base.inheritance_column = 'some_column'.)
45
+ * Rename related indexes on `rename_table` and `rename_column`. This
46
+ does not affect indexes with custom names.
92
47
 
93
- *chapmajs + Takehiro Adachi*
48
+ *Yves Senn*
94
49
 
95
- * Fix mysql2 adapter raises the correct exception when executing a query on a
96
- closed connection.
50
+ * Prevent the creation of indices with too long names, which cause
51
+ internal operations to fail (sqlite3 adapter only). The method
52
+ `allowed_index_name_length` defines the length limit enforced by
53
+ rails. It's value defaults to `index_name_length` but can vary per adapter.
54
+ Fixes #8264.
97
55
 
98
56
  *Yves Senn*
99
57
 
100
- * Fixes bug where `Company.new.contract_ids` would incorrectly load
101
- all non-associated contracts.
58
+ * Fixing issue #776.
102
59
 
103
- Example:
60
+ Memory bloat in transactions is handled by having the transaction hold only
61
+ the AR objects which it absolutely needs to know about. These are the AR
62
+ objects with callbacks (they need to be updated as soon as something in the
63
+ transaction occurs).
104
64
 
105
- company = Company.new # Company has many :contracts
65
+ All other AR objects can be updated lazily by keeping a reference to a
66
+ TransactionState object. If an AR object gets inside a transaction, then
67
+ the transaction will add its TransactionState to the AR object. When the
68
+ user makes a call to some attribute on an AR object (which has no
69
+ callbacks) associated with a transaction, the AR object will call the
70
+ sync_with_transaction_state method and make sure it is up to date with the
71
+ transaction. After it has synced with the transaction state, the AR object
72
+ will return the attribute that was requested.
106
73
 
107
- # before
108
- company.contract_ids # => SELECT ... WHERE `contracts`.`company_id` IS NULL
74
+ Most of the logic in the changes are used to handle multiple transactions,
75
+ in which case the AR object has to recursively follow parent pointers of
76
+ TransactionState objects.
109
77
 
110
- # after
111
- company.contract_ids # => []
78
+ *John Wang*
112
79
 
113
- *Jared Armstrong*
114
-
115
- * Fix the `:primary_key` option for `has_many` associations.
116
- Fixes #10693.
80
+ * Descriptive error message when the necessary AR adapter gem was not found.
81
+ Fixes #7313.
117
82
 
118
83
  *Yves Senn*
119
84
 
120
- * fixes bug introduced by #3329. Now, when autosaving associations,
121
- deletions happen before inserts and saves. This prevents a 'duplicate
122
- unique value' database error that would occur if a record being created had
123
- the same value on a unique indexed field as that of a record being destroyed.
124
-
125
- Backport of #10417
126
-
127
- *Johnny Holton*
85
+ * Active Record now raises an error when blank arguments are passed to query
86
+ methods for which blank arguments do not make sense.
128
87
 
129
- * Fix that under some conditions, Active Record could produce invalid SQL of the sort:
130
- "SELECT DISTINCT DISTINCT".
131
-
132
- Backport of #6792.
133
-
134
- *Ben Woosley*
88
+ Example:
135
89
 
136
- * Require `ActiveRecord::Base` in railtie hooks for rake_tasks, console and runner to
137
- avoid circular constant loading issues.
90
+ Post.includes() # => raises error
138
91
 
139
- Backport #7695.
92
+ *John Wang*
140
93
 
141
- Fixes #7683 and #882
94
+ * Simplified type casting code for timezone aware attributes to use the
95
+ `in_time_zone` method if it is available. This introduces a subtle change
96
+ of behavior when using `Date` instances as they are directly converted to
97
+ `ActiveSupport::TimeWithZone` instances without first being converted to
98
+ `Time` instances. For example:
142
99
 
143
- *Ben Holley*
100
+ # Rails 3.2 behavior
101
+ >> Date.today.to_time.in_time_zone
102
+ => Wed, 13 Feb 2013 07:00:00 UTC +00:00
144
103
 
145
- * Maintain context for joins within ActiveRecord::Relation merges.
146
- Backport #10164.
104
+ # Rails 4.0 behavior
105
+ >> Date.today.in_time_zone
106
+ => Wed, 13 Feb 2013 00:00:00 UTC +00:00
147
107
 
148
- *Neeraj Singh + Andrew Horner*
108
+ On the plus side it now behaves the same whether you pass a `String` date
109
+ or an actual `Date` instance. For example:
149
110
 
150
- * Make sure the `EXPLAIN` command is never triggered by a `select_db` call.
111
+ # Rails 3.2 behavior
112
+ >> Date.civil(2013, 2, 13).to_time.in_time_zone
113
+ => Wed, 13 Feb 2013 07:00:00 UTC +00:00
114
+ >> Time.zone.parse("2013-02-13")
115
+ => Wed, 13 Feb 2013 00:00:00 UTC +00:00
151
116
 
152
- *Daniel Schierbeck*
117
+ # Rails 4.0 behavior
118
+ >> Date.civil(2013, 2, 13).in_time_zone
119
+ => Wed, 13 Feb 2013 00:00:00 UTC +00:00
120
+ >> "2013-02-13".in_time_zone
121
+ => Wed, 13 Feb 2013 00:00:00 UTC +00:00
153
122
 
154
- * Revert changes on `pluck` that was ignoring the select clause when the relation already
155
- has one. This caused a regression since it changed the behavior in a stable release.
123
+ If you need the old behavior you can convert the dates to times manually.
124
+ For example:
156
125
 
157
- Fixes #9777.
126
+ >> Post.new(created_at: Date.today).created_at
127
+ => Wed, 13 Feb 2013 00:00:00 UTC +00:00
158
128
 
159
- *Rafael Mendonça França*
129
+ >> Post.new(created_at: Date.today.to_time).created_at
130
+ => Wed, 13 Feb 2013 07:00:00 UTC +00:00
160
131
 
161
- * Confirm a record has not already been destroyed before decrementing counter cache.
132
+ *Andrew White*
162
133
 
163
- *Ben Tucker*
134
+ * Preloading `has_many :through` associations with conditions won't
135
+ cache the `:through` association. This will prevent invalid
136
+ subsets to be cached.
137
+ Fixes #8423.
164
138
 
165
- * Default values for PostgreSQL bigint types now get parsed and dumped to the
166
- schema correctly.
167
- Backport #10098.
139
+ Example:
168
140
 
169
- *Erik Peterson*
141
+ class User
142
+ has_many :posts
143
+ has_many :recent_comments, -> { where('created_at > ?', 1.week.ago) }, :through => :posts
144
+ end
170
145
 
171
- * Removed warning when `auto_explain_threshold_in_seconds` is set and the
172
- connection adapter doesn't support explain.
173
- This is causing a regression since the Active Record Railtie is trying to
174
- connect to the development database in the application boot.
146
+ a_user = User.includes(:recent_comments).first
175
147
 
176
- *Rafael Mendonça França*
148
+ # This is preloaded.
149
+ a_user.recent_comments
177
150
 
178
- * Do not reset `inheritance_column` when it's set explicitly.
179
- Backport of #5327.
151
+ # This is not preloaded, fetched now.
152
+ a_user.posts
180
153
 
181
- *kennyj + Fred Wu*
154
+ *Yves Senn*
182
155
 
183
- * Fix a problem wrong exception is occured
184
- when raising no translatable exception in PostgreSQL.
156
+ * Don't run `after_commit` callbacks when creating through an association
157
+ if saving the record fails.
185
158
 
186
- *kennyj*
159
+ *James Miller*
187
160
 
188
- * Resets the postgres search path in the structure.sql after the structure
189
- is dumped in order to find schema_migrations table when multiples schemas
190
- are used.
191
- Fixes #9796.
161
+ * Allow store accessors to be overrided like other attribute methods, e.g.:
192
162
 
193
- *Juan M. Cuello + Dembskiy Alexander*
163
+ class User < ActiveRecord::Base
164
+ store :settings, accessors: [ :color, :homepage ], coder: JSON
194
165
 
195
- * Reload the association target if it's stale. `@stale_state` should be nil
196
- when a model isn't saved.
197
- Fixes #7526.
166
+ def color
167
+ super || 'red'
168
+ end
169
+ end
198
170
 
199
- *Larry Lv*
171
+ *Sergey Nartimov*
200
172
 
201
- * Don't read CSV files during execution of `db:fixtures:load`. CSV support for
202
- fixtures was removed some time ago but the task was still loading them, even
203
- though later the code was looking for the related yaml file instead.
173
+ * Quote numeric values being compared to non-numeric columns. Otherwise,
174
+ in some database, the string column values will be coerced to a numeric
175
+ allowing 0, 0.0 or false to match any string starting with a non-digit.
204
176
 
205
- *kennyj*
177
+ Example:
206
178
 
179
+ App.where(apikey: 0) # => SELECT * FROM users WHERE apikey = '0'
207
180
 
208
- ## Rails 3.2.13 (Mar 18, 2013) ##
181
+ *Dylan Smith*
209
182
 
210
- * Chaining multiple preloaded scopes will correctly preload all the scopes
211
- at the same time.
183
+ * Schema dumper supports dumping the enabled database extensions to `schema.rb`
184
+ (currently only supported by postgresql).
212
185
 
213
- *Chris Geihsler*
186
+ *Justin George*
214
187
 
215
- * Reverted 921a296a3390192a71abeec6d9a035cc6d1865c8, 'Quote numeric values
216
- compared to string columns.' This caused several regressions.
188
+ * The database adpters now converts the options passed thought `DATABASE_URL`
189
+ environment variable to the proper Ruby types before using. For example, SQLite requires
190
+ that the timeout value is an integer, and PostgreSQL requires that the
191
+ prepared_statements option is a boolean. These now work as expected:
217
192
 
218
- *Steve Klabnik*
193
+ Example:
219
194
 
220
- * Fix overriding of attributes by `default_scope` on `ActiveRecord::Base#dup`.
195
+ DATABASE_URL=sqlite3://localhost/test_db?timeout=500
196
+ DATABASE_URL=postgresql://localhost/test_db?prepared_statements=false
221
197
 
222
- *Hiroshige UMINO*
198
+ *Aaron Stone + Rafael Mendonça França*
223
199
 
224
- * Fix issue with overriding Active Record reader methods with a composed object
225
- and using that attribute as the scope of a `uniqueness_of` validation.
226
- Backport #7072.
200
+ * `Relation#merge` now only overwrites where values on the LHS of the
201
+ merge. Consider:
227
202
 
228
- *Peter Brown*
203
+ left = Person.where(age: [13, 14, 15])
204
+ right = Person.where(age: [13, 14]).where(age: [14, 15])
229
205
 
230
- * Sqlite now preserves custom primary keys when copying or altering tables.
231
- Fixes #9367.
232
- Backport #2312.
206
+ `left` results in the following SQL:
233
207
 
234
- *Sean Scally + Yves Senn*
208
+ WHERE age IN (13, 14, 15)
235
209
 
236
- * Preloading `has_many :through` associations with conditions won't
237
- cache the `:through` association. This will prevent invalid
238
- subsets to be cached.
239
- Fixes #8423.
240
- Backport #9252.
210
+ `right` results in the following SQL:
241
211
 
242
- Example:
212
+ WHERE age IN (13, 14) AND age IN (14, 15)
243
213
 
244
- class User
245
- has_many :posts
246
- has_many :recent_comments, -> { where('created_at > ?', 1.week.ago) }, :through => :posts
247
- end
214
+ Previously, `left.merge(right)` would result in all but the last
215
+ condition being removed:
248
216
 
249
- a_user = User.includes(:recent_comments).first
217
+ WHERE age IN (14, 15)
250
218
 
251
- # this is preloaded
252
- a_user.recent_comments
219
+ Now it results in the LHS condition(s) for `age` being removed, but
220
+ the RHS remains as it is:
253
221
 
254
- # fetching the recent_comments through the posts association won't preload it.
255
- a_user.posts
222
+ WHERE age IN (13, 14) AND age IN (14, 15)
256
223
 
257
- *Yves Senn*
224
+ *Jon Leighton*
258
225
 
259
226
  * Fix handling of dirty time zone aware attributes
260
227
 
@@ -282,54 +249,55 @@
282
249
  order.changed? # => false, used to return true
283
250
  end
284
251
 
285
- Backport of #9073
286
- Fixes #8898
287
-
288
252
  *Lilibeth De La Cruz*
289
253
 
290
- * Fix counter cache columns not updated when replacing `has_many :through`
291
- associations.
292
- Backport #8400.
293
- Fix #7630.
254
+ * When `#count` is used in conjunction with `#uniq` we perform `count(:distinct => true)`.
255
+ Fixes #6865.
294
256
 
295
- *Matthew Robertson*
257
+ Example:
296
258
 
297
- * Don't update `column_defaults` when calling destructive methods on column with default value.
298
- Backport c517602.
299
- Fix #6115.
259
+ relation.uniq.count # => SELECT COUNT(DISTINCT *)
300
260
 
301
- *Piotr Sarnacki + Aleksey Magusev + Alan Daud*
261
+ *Yves Senn + Kaspar Schiess*
302
262
 
303
- * When `#count` is used in conjunction with `#uniq` we perform `count(:distinct => true)`.
304
- Fix #6865.
263
+ * PostgreSQL ranges type support. Includes: int4range, int8range,
264
+ numrange, tsrange, tstzrange, daterange
265
+
266
+ Ranges can be created with inclusive and exclusive bounds.
305
267
 
306
268
  Example:
307
269
 
308
- relation.uniq.count # => SELECT COUNT(DISTINCT *)
270
+ create_table :Room do |t|
271
+ t.daterange :availability
272
+ end
309
273
 
310
- *Yves Senn + Kaspar Schiess*
274
+ Room.create(availability: (Date.today..Float::INFINITY))
275
+ Room.first.availability # => Wed, 19 Sep 2012..Infinity
311
276
 
312
- * Fix `ActiveRecord::Relation#pluck` when columns or tables are reserved words.
313
- Backport #7536.
314
- Fix #8968.
277
+ One thing to note: Range class does not support exclusive lower
278
+ bound.
315
279
 
316
- *Ian Lesperance + Yves Senn + Kaspar Schiess*
280
+ *Alexander Grebennik*
317
281
 
318
- * Don't run explain on slow queries for database adapters that don't support it.
319
- Backport #6197.
282
+ * Added a state instance variable to each transaction. Will allow other objects
283
+ to know whether a transaction has been committed or rolled back.
320
284
 
321
- *Blake Smith*
285
+ *John Wang*
322
286
 
323
- * Revert round usec when comparing timestamp attributes in the dirty tracking.
324
- Fixes #8460.
287
+ * Collection associations `#empty?` always respects builded records.
288
+ Fixes #8879.
325
289
 
326
- *Andrew White*
290
+ Example:
327
291
 
328
- * Revert creation of through association models when using `collection=[]`
329
- on a `has_many :through` association from an unsaved model.
330
- Fix #7661, #8269.
292
+ widget = Widget.new
293
+ widget.things.build
294
+ widget.things.empty? # => false
331
295
 
332
- *Ernie Miller*
296
+ *Yves Senn*
297
+
298
+ * Support for PostgreSQL's `ltree` data type.
299
+
300
+ *Rob Worley*
333
301
 
334
302
  * Fix undefined method `to_i` when calling `new` on a scope that uses an
335
303
  Array; Fix FloatDomainError when setting integer column to NaN.
@@ -337,6 +305,36 @@
337
305
 
338
306
  *Jason Stirk + Tristan Harward*
339
307
 
308
+ * Rename `update_attributes` to `update`, keep `update_attributes` as an alias for `update` method.
309
+ This is a soft-deprecation for `update_attributes`, although it will still work without any
310
+ deprecation message in 4.0 is recommended to start using `update` since `update_attributes` will be
311
+ deprecated and removed in future versions of Rails.
312
+
313
+ *Amparo Luna + Guillermo Iguaran*
314
+
315
+ * `after_commit` and `after_rollback` now validate the `:on` option and raise an `ArgumentError`
316
+ if it is not one of `:create`, `:destroy` or `:update`
317
+
318
+ *Pascal Friederich*
319
+
320
+ * Improve ways to write `change` migrations, making the old `up` & `down` methods no longer necessary.
321
+
322
+ * The methods `drop_table` and `remove_column` are now reversible, as long as the necessary information is given.
323
+ The method `remove_column` used to accept multiple column names; instead use `remove_columns` (which is not reversible).
324
+ The method `change_table` is also reversible, as long as its block doesn't call `remove`, `change` or `change_default`
325
+
326
+ * New method `reversible` makes it possible to specify code to be run when migrating up or down.
327
+ See the [Guide on Migration](https://github.com/rails/rails/blob/master/guides/source/migrations.md#using-the-reversible-method)
328
+
329
+ * New method `revert` will revert a whole migration or the given block.
330
+ If migrating down, the given migration / block is run normally.
331
+ See the [Guide on Migration](https://github.com/rails/rails/blob/master/guides/source/migrations.md#reverting-previous-migrations)
332
+
333
+ Attempting to revert the methods `execute`, `remove_columns` and `change_column` will now
334
+ raise an `IrreversibleMigration` instead of actually executing them without any output.
335
+
336
+ *Marc-André Lafortune*
337
+
340
338
  * Serialized attributes can be serialized in integer columns.
341
339
  Fix #8575.
342
340
 
@@ -344,27 +342,58 @@
344
342
 
345
343
  * Keep index names when using `alter_table` with sqlite3.
346
344
  Fix #3489.
347
- Backport #8522.
348
345
 
349
346
  *Yves Senn*
350
347
 
348
+ * Add ability for postgresql adapter to disable user triggers in `disable_referential_integrity`.
349
+ Fix #5523.
350
+
351
+ *Gary S. Weaver*
352
+
353
+ * Added support for `validates_uniqueness_of` in PostgreSQL array columns.
354
+ Fixes #8075.
355
+
356
+ *Pedro Padron*
357
+
358
+ * Allow int4range and int8range columns to be created in PostgreSQL and properly convert to/from database.
359
+
360
+ *Alexey Vasiliev aka leopard*
361
+
362
+ * Do not log the binding values for binary columns.
363
+
364
+ *Matthew M. Boedicker*
365
+
366
+ * Fix counter cache columns not updated when replacing `has_many :through`
367
+ associations.
368
+
369
+ *Matthew Robertson*
370
+
351
371
  * Recognize migrations placed in directories containing numbers and 'rb'.
352
- Fix #8492.
353
- Backport of #8500.
372
+ Fix #8492
354
373
 
355
374
  *Yves Senn*
356
375
 
357
376
  * Add `ActiveRecord::Base.cache_timestamp_format` class attribute to control
358
- the format of the timestamp value in the cache key.
359
- This allows users to improve the precision of the cache key.
377
+ the format of the timestamp value in the cache key. Defaults to `:nsec`.
360
378
  Fixes #8195.
361
379
 
362
380
  *Rafael Mendonça França*
363
381
 
364
- * Add `:nsec` date format. This can be used to improve the precision of cache key.
365
- Please note that this format only works with Ruby 1.9, Ruby 1.8 will ignore it completely.
382
+ * Session variables can be set for the `mysql`, `mysql2`, and `postgresql` adapters
383
+ in the `variables: <hash>` parameter in `config/database.yml`. The key-value pairs of this
384
+ hash will be sent in a `SET key = value` query on new database connections. See also:
385
+ http://dev.mysql.com/doc/refman/5.0/en/set-statement.html
386
+ http://www.postgresql.org/docs/8.3/static/sql-set.html
387
+
388
+ *Aaron Stone*
366
389
 
367
- *Jamie Gaskins*
390
+ * Allow `Relation#where` with no arguments to be chained with new `not` query method.
391
+
392
+ Example:
393
+
394
+ Developer.where.not(name: 'Aaron')
395
+
396
+ *Akira Matsuda*
368
397
 
369
398
  * Unscope `update_column(s)` query to ignore default scope.
370
399
 
@@ -374,7 +403,7 @@
374
403
  to the update query.
375
404
 
376
405
  class User < ActiveRecord::Base
377
- default_scope where(active: true)
406
+ default_scope -> { where(active: true) }
378
407
  end
379
408
 
380
409
  user = User.first
@@ -388,12 +417,16 @@
388
417
 
389
418
  user.update_column(:active, true) # => true
390
419
 
391
- Backport of #8436 fix.
420
+ Fixes #8436.
392
421
 
393
422
  *Carlos Antonio da Silva*
394
423
 
395
- * Fix performance problem with primary_key method in PostgreSQL adapter when having many schemas.
396
- Uses pg_constraint table instead of pg_depend table which has many records in general.
424
+ * SQLite adapter no longer corrupts binary data if the data contains `%00`.
425
+
426
+ *Chris Feist*
427
+
428
+ * Fix performance problem with `primary_key` method in PostgreSQL adapter when having many schemas.
429
+ Uses `pg_constraint` table instead of `pg_depend` table which has many records in general.
397
430
  Fix #8414
398
431
 
399
432
  *kennyj*
@@ -401,67 +434,73 @@
401
434
  * Do not instantiate intermediate Active Record objects when eager loading.
402
435
  These records caused `after_find` to run more than expected.
403
436
  Fix #3313
404
- Backport of #8403
405
437
 
406
438
  *Yves Senn*
407
439
 
408
- * Fix `pluck` to work with joins. Backport of #4942.
440
+ * Add STI support to init and building associations.
441
+ Allows you to do `BaseClass.new(type: "SubClass")` as well as
442
+ `parent.children.build(type: "SubClass")` or `parent.build_child`
443
+ to initialize an STI subclass. Ensures that the class name is a
444
+ valid class and that it is in the ancestors of the super class
445
+ that the association is expecting.
409
446
 
410
- *Carlos Antonio da Silva*
447
+ *Jason Rush*
411
448
 
412
- * Fix a problem with `translate_exception` method in a non English environment.
413
- Backport of #6397.
449
+ * Observers was extracted from Active Record as `rails-observers` gem.
414
450
 
415
- *kennyj*
451
+ *Rafael Mendonça França*
452
+
453
+ * Ensure that associations take a symbol argument. *Steve Klabnik*
416
454
 
417
- * Fix dirty attribute checks for TimeZoneConversion with nil and blank
455
+ * Fix dirty attribute checks for `TimeZoneConversion` with nil and blank
418
456
  datetime attributes. Setting a nil datetime to a blank string should not
419
- result in a change being flagged.
420
- Fixes #8310.
421
- Backport of #8311.
457
+ result in a change being flagged. Fix #8310
422
458
 
423
459
  *Alisdair McDiarmid*
424
460
 
425
- * Prevent mass assignment to the type column of polymorphic associations when using `build`.
426
- Fixes #8265.
427
- Backport of #8291.
461
+ * Prevent mass assignment to the type column of polymorphic associations when using `build`
462
+ Fix #8265
428
463
 
429
464
  *Yves Senn*
430
465
 
431
- * When running migrations on Postgresql, the `:limit` option for `binary` and `text` columns is
432
- silently dropped.
433
- Previously, these migrations caused sql exceptions, because Postgresql doesn't support limits
434
- on these types.
466
+ * Deprecate calling `Relation#sum` with a block. To perform a calculation over
467
+ the array result of the relation, use `to_a.sum(&block)`.
468
+
469
+ *Carlos Antonio da Silva*
470
+
471
+ * Fix postgresql adapter to handle BC timestamps correctly
472
+
473
+ HistoryEvent.create!(name: "something", occured_at: Date.new(0) - 5.years)
474
+
475
+ *Bogdan Gusiev*
476
+
477
+ * When running migrations on Postgresql, the `:limit` option for `binary` and `text` columns is silently dropped.
478
+ Previously, these migrations caused sql exceptions, because Postgresql doesn't support limits on these types.
435
479
 
436
480
  *Victor Costan*
437
481
 
438
- * `#pluck` can be used on a relation with `select` clause.
439
- Fixes #7551.
440
- Backport of #8176.
482
+ * Don't change STI type when calling `ActiveRecord::Base#becomes`.
483
+ Add `ActiveRecord::Base#becomes!` with the previous behavior.
441
484
 
442
- Example:
485
+ See #3023 for more information.
443
486
 
444
- Topic.select([:approved, :id]).order(:id).pluck(:id)
487
+ *Thomas Hollstegge*
445
488
 
446
- *Yves Senn*
489
+ * `rename_index` can be used inside a `change_table` block.
447
490
 
448
- * Use `nil?` instead of `blank?` to check whether dynamic finder with a bang
449
- should raise RecordNotFound.
450
- Fixes #7238.
491
+ change_table :accounts do |t|
492
+ t.rename_index :user_id, :account_id
493
+ end
451
494
 
452
- *Nikita Afanasenko*
495
+ *Jarek Radosz*
453
496
 
454
- * Fix deleting from a HABTM join table upon destroying an object of a model
455
- with optimistic locking enabled.
456
- Fixes #5332.
497
+ * `#pluck` can be used on a relation with `select` clause. Fix #7551
457
498
 
458
- *Nick Rogers*
499
+ Example:
459
500
 
460
- * Use query cache/uncache when using ENV["DATABASE_URL"].
461
- Fixes #6951.
462
- Backport of #8074.
501
+ Topic.select([:approved, :id]).order(:id).pluck(:id)
463
502
 
464
- *kennyj*
503
+ *Yves Senn*
465
504
 
466
505
  * Do not create useless database transaction when building `has_one` association.
467
506
 
@@ -470,114 +509,150 @@
470
509
  User.has_one :profile
471
510
  User.new.build_profile
472
511
 
473
- Backport of #8154.
474
-
475
512
  *Bogdan Gusiev*
476
513
 
477
- * `AR::Base#attributes_before_type_cast` now returns unserialized values for serialized attributes.
514
+ * `:counter_cache` option for `has_many` associations to support custom named counter caches.
515
+ Fix #7993
478
516
 
479
- *Nikita Afanasenko*
517
+ *Yves Senn*
480
518
 
481
- * Fix issue that raises `NameError` when overriding the `accepts_nested_attributes` in child classes.
519
+ * Deprecate the possibility to pass a string as third argument of `add_index`.
520
+ Pass `unique: true` instead.
482
521
 
483
- Before:
522
+ add_index(:users, :organization_id, unique: true)
484
523
 
485
- class Shared::Person < ActiveRecord::Base
486
- has_one :address
524
+ *Rafael Mendonça França*
487
525
 
488
- accepts_nested_attributes :address, :reject_if => :all_blank
489
- end
526
+ * Raise an `ArgumentError` when passing an invalid option to `add_index`.
490
527
 
491
- class Person < Shared::Person
492
- accepts_nested_attributes :address
493
- end
528
+ *Rafael Mendonça França*
494
529
 
495
- Person
496
- #=> NameError: method `address_attributes=' not defined in Person
530
+ * Fix `find_in_batches` crashing when IDs are strings and start option is not specified.
497
531
 
498
- After:
532
+ *Alexis Bernard*
499
533
 
500
- Person
501
- #=> Person(id: integer, ...)
534
+ * `AR::Base#attributes_before_type_cast` now returns unserialized values for serialized attributes.
502
535
 
503
- Fixes #8131.
536
+ *Nikita Afanasenko*
504
537
 
505
- *Gabriel Sobrinho, Ricardo Henrique*
538
+ * Use query cache/uncache when using `DATABASE_URL`.
539
+ Fix #6951.
506
540
 
541
+ *kennyj*
507
542
 
508
- ## Rails 3.2.12 (Feb 11, 2013) ##
543
+ * Fix bug where `update_columns` and `update_column` would not let you update the primary key column.
509
544
 
510
- * Quote numeric values being compared to non-numeric columns. Otherwise,
511
- in some database, the string column values will be coerced to a numeric
512
- allowing 0, 0.0 or false to match any string starting with a non-digit.
545
+ *Henrik Nyh*
513
546
 
514
- Example:
547
+ * The `create_table` method raises an `ArgumentError` when the primary key column is redefined.
548
+ Fix #6378
515
549
 
516
- App.where(apikey: 0) # => SELECT * FROM users WHERE apikey = '0'
550
+ *Yves Senn*
517
551
 
518
- *Dylan Smith*
552
+ * `ActiveRecord::AttributeMethods#[]` raises `ActiveModel::MissingAttributeError`
553
+ error if the given attribute is missing. Fixes #5433.
519
554
 
555
+ class Person < ActiveRecord::Base
556
+ belongs_to :company
557
+ end
520
558
 
521
- ## Rails 3.2.11 (Jan 8, 2013) ##
559
+ # Before:
560
+ person = Person.select('id').first
561
+ person[:name] # => nil
562
+ person.name # => ActiveModel::MissingAttributeError: missing_attribute: name
563
+ person[:company_id] # => nil
564
+ person.company # => nil
522
565
 
523
- * Fix querying with an empty hash *Damien Mathieu* [CVE-2013-0155]
566
+ # After:
567
+ person = Person.select('id').first
568
+ person[:name] # => ActiveModel::MissingAttributeError: missing_attribute: name
569
+ person.name # => ActiveModel::MissingAttributeError: missing_attribute: name
570
+ person[:company_id] # => ActiveModel::MissingAttributeError: missing_attribute: company_id
571
+ person.company # => ActiveModel::MissingAttributeError: missing_attribute: company_id
524
572
 
573
+ *Francesco Rodriguez*
525
574
 
526
- ## Rails 3.2.10 (Jan 2, 2013) ##
575
+ * Small binary fields use the `VARBINARY` MySQL type, instead of `TINYBLOB`.
527
576
 
528
- * CVE-2012-5664 options hashes should only be extracted if there are extra
529
- parameters
577
+ *Victor Costan*
530
578
 
579
+ * Decode URI encoded attributes on database connection URLs.
531
580
 
532
- ## Rails 3.2.9 (Nov 12, 2012) ##
581
+ *Shawn Veader*
533
582
 
534
- * Fix `find_in_batches` crashing when IDs are strings and start option is not specified.
583
+ * Add `find_or_create_by`, `find_or_create_by!` and
584
+ `find_or_initialize_by` methods to `Relation`.
535
585
 
536
- *Alexis Bernard*
586
+ These are similar to the `first_or_create` family of methods, but
587
+ the behaviour when a record is created is slightly different:
537
588
 
538
- * Fix issue with collection associations calling first(n)/last(n) and attempting
539
- to set the inverse association when `:inverse_of` was used. Fixes #8087.
589
+ User.where(first_name: 'Penélope').first_or_create
540
590
 
541
- *Carlos Antonio da Silva*
591
+ will execute:
542
592
 
543
- * Fix bug when Column is trying to type cast boolean values to integer.
544
- Fixes #8067.
593
+ User.where(first_name: 'Penélope').create
545
594
 
546
- *Rafael Mendonça França*
595
+ Causing all the `create` callbacks to execute within the context of
596
+ the scope. This could affect queries that occur within callbacks.
547
597
 
548
- * Fix bug where `rake db:test:prepare` tries to load the structure.sql into development database.
549
- Fixes #8032.
598
+ User.find_or_create_by(first_name: 'Penélope')
550
599
 
551
- *Grace Liu + Rafael Mendonça França*
600
+ will execute:
552
601
 
553
- * Fixed support for `DATABASE_URL` environment variable for rake db tasks. *Grace Liu*
602
+ User.create(first_name: 'Penélope')
554
603
 
555
- * Fix bug where `update_columns` and `update_column` would not let you update the primary key column.
604
+ Which obviously does not affect the scoping of queries within
605
+ callbacks.
556
606
 
557
- *Henrik Nyh*
607
+ The `find_or_create_by` version also reads better, frankly.
558
608
 
559
- * Decode URI encoded attributes on database connection URLs.
609
+ If you need to add extra attributes during create, you can do one of:
560
610
 
561
- *Shawn Veader*
611
+ User.create_with(active: true).find_or_create_by(first_name: 'Jon')
612
+ User.find_or_create_by(first_name: 'Jon') { |u| u.active = true }
562
613
 
563
- * Fix AR#dup to nullify the validation errors in the dup'ed object. Previously the original
564
- and the dup'ed object shared the same errors.
614
+ The `first_or_create` family of methods have been nodoc'ed in favour
615
+ of this API. They may be deprecated in the future but their
616
+ implementation is very small and it's probably not worth putting users
617
+ through lots of annoying deprecation warnings.
565
618
 
566
- *Christian Seiler*
619
+ *Jon Leighton*
620
+
621
+ * Fix bug with presence validation of associations. Would incorrectly add duplicated errors
622
+ when the association was blank. Bug introduced in 1fab518c6a75dac5773654646eb724a59741bc13.
623
+
624
+ *Scott Willson*
567
625
 
568
- * Synchronize around deleting from the reserved connections hash.
569
- Fixes #7955
626
+ * Fix bug where sum(expression) returns string '0' for no matching records.
627
+ Fixes #7439
570
628
 
571
- * PostgreSQL adapter correctly fetches default values when using
572
- multiple schemas and domains in a db. Fixes #7914
629
+ *Tim Macfarlane*
630
+
631
+ * PostgreSQL adapter correctly fetches default values when using multiple schemas and domains in a db. Fixes #7914
573
632
 
574
633
  *Arturo Pie*
575
634
 
576
- * Fix deprecation notice when loading a collection association that
577
- selects columns from other tables, if a new record was previously
578
- built using that association.
635
+ * Learn ActiveRecord::QueryMethods#order work with hash arguments
579
636
 
580
- *Ernie Miller*
637
+ When symbol or hash passed we convert it to Arel::Nodes::Ordering.
638
+ If we pass invalid direction(like name: :DeSc) ActiveRecord::QueryMethods#order will raise an exception
639
+
640
+ User.order(:name, email: :desc)
641
+ # SELECT "users".* FROM "users" ORDER BY "users"."name" ASC, "users"."email" DESC
642
+
643
+ *Tima Maslyuchenko*
644
+
645
+ * Rename `ActiveRecord::Fixtures` class to `ActiveRecord::FixtureSet`.
646
+ Instances of this class normally hold a collection of fixtures (records)
647
+ loaded either from a single YAML file, or from a file and a folder
648
+ with the same name. This change make the class name singular and makes
649
+ the class easier to distinguish from the modules like
650
+ `ActiveRecord::TestFixtures`, which operates on multiple fixture sets,
651
+ or `DelegatingFixtures`, `::Fixtures`, etc.,
652
+ and from the class `ActiveRecord::Fixture`, which corresponds to a single
653
+ fixture.
654
+
655
+ *Alexey Muranov*
581
656
 
582
657
  * The postgres adapter now supports tables with capital letters.
583
658
  Fix #5920
@@ -606,15 +681,90 @@
606
681
 
607
682
  *lulalala*
608
683
 
609
- * ConnectionPool recognizes checkout_timeout spec key as taking
610
- precedence over legacy wait_timeout spec key, can be used to avoid
611
- conflict with mysql2 use of wait_timeout. Closes #7684.
684
+ * Support for partial inserts.
685
+
686
+ When inserting new records, only the fields which have been changed
687
+ from the defaults will actually be included in the INSERT statement.
688
+ The other fields will be populated by the database.
689
+
690
+ This is more efficient, and also means that it will be safe to
691
+ remove database columns without getting subsequent errors in running
692
+ app processes (so long as the code in those processes doesn't
693
+ contain any references to the removed column).
694
+
695
+ The `partial_updates` configuration option is now renamed to
696
+ `partial_writes` to reflect the fact that it now impacts both inserts
697
+ and updates.
698
+
699
+ *Jon Leighton*
700
+
701
+ * Allow before and after validations to take an array of lifecycle events
702
+
703
+ *John Foley*
704
+
705
+ * Support for specifying transaction isolation level
706
+
707
+ If your database supports setting the isolation level for a transaction, you can set
708
+ it like so:
709
+
710
+ Post.transaction(isolation: :serializable) do
711
+ # ...
712
+ end
713
+
714
+ Valid isolation levels are:
715
+
716
+ * `:read_uncommitted`
717
+ * `:read_committed`
718
+ * `:repeatable_read`
719
+ * `:serializable`
720
+
721
+ You should consult the documentation for your database to understand the
722
+ semantics of these different levels:
723
+
724
+ * http://www.postgresql.org/docs/9.1/static/transaction-iso.html
725
+ * https://dev.mysql.com/doc/refman/5.0/en/set-transaction.html
726
+
727
+ An `ActiveRecord::TransactionIsolationError` will be raised if:
728
+
729
+ * The adapter does not support setting the isolation level
730
+ * You are joining an existing open transaction
731
+ * You are creating a nested (savepoint) transaction
732
+
733
+ The mysql, mysql2 and postgresql adapters support setting the transaction
734
+ isolation level. However, support is disabled for mysql versions below 5,
735
+ because they are affected by a bug (http://bugs.mysql.com/bug.php?id=39170)
736
+ which means the isolation level gets persisted outside the transaction.
737
+
738
+ *Jon Leighton*
739
+
740
+ * `ActiveModel::ForbiddenAttributesProtection` is included by default
741
+ in Active Record models. Check the docs of `ActiveModel::ForbiddenAttributesProtection`
742
+ for more details.
743
+
744
+ *Guillermo Iguaran*
745
+
746
+ * Remove integration between Active Record and
747
+ `ActiveModel::MassAssignmentSecurity`, `protected_attributes` gem
748
+ should be added to use `attr_accessible`/`attr_protected`. Mass
749
+ assignment options has been removed from all the AR methods that
750
+ used it (ex. `AR::Base.new`, `AR::Base.create`, `AR::Base#update_attributes`, etc).
612
751
 
613
- *jrochkind*
752
+ *Guillermo Iguaran*
614
753
 
615
- * Rename field_changed? to _field_changed? so that users can create a field named field
754
+ * Fix the return of querying with an empty hash.
755
+ Fix #6971.
756
+
757
+ User.where(token: {})
758
+
759
+ Before:
616
760
 
617
- *Akira Matsuda*, backported by *Steve Klabnik*
761
+ #=> SELECT * FROM users;
762
+
763
+ After:
764
+
765
+ #=> SELECT * FROM users WHERE 1=0;
766
+
767
+ *Damien Mathieu*
618
768
 
619
769
  * Fix creation of through association models when using `collection=[]`
620
770
  on a `has_many :through` association from an unsaved model.
@@ -623,115 +773,250 @@
623
773
  *Ernie Miller*
624
774
 
625
775
  * Explain only normal CRUD sql (select / update / insert / delete).
626
- Fix problem that explains unexplainable sql. Closes #7544 #6458.
776
+ Fix problem that explains unexplainable sql.
777
+ Closes #7544 #6458.
627
778
 
628
779
  *kennyj*
629
780
 
630
- * Backport test coverage to ensure that PostgreSQL auto-reconnect functionality
631
- remains healthy.
781
+ * You can now override the generated accessor methods for stored attributes
782
+ and reuse the original behavior with `read_store_attribute` and `write_store_attribute`,
783
+ which are counterparts to `read_attribute` and `write_attribute`.
784
+
785
+ *Matt Jones*
786
+
787
+ * Accept `belongs_to` (including polymorphic) association keys in queries.
632
788
 
633
- *Steve Jorgensen*
789
+ The following queries are now equivalent:
634
790
 
635
- * Use config['encoding'] instead of config['charset'] when executing
636
- databases.rake in the mysql/mysql2. A correct option for a database.yml
637
- is 'encoding'.
791
+ Post.where(author: author)
792
+ Post.where(author_id: author)
793
+
794
+ PriceEstimate.where(estimate_of: treasure)
795
+ PriceEstimate.where(estimate_of_type: 'Treasure', estimate_of_id: treasure)
796
+
797
+ *Peter Brown*
798
+
799
+ * Use native `mysqldump` command instead of `structure_dump` method
800
+ when dumping the database structure to a sql file. Fixes #5547.
638
801
 
639
802
  *kennyj*
640
803
 
641
- * Fix ConnectionAdapters::Column.type_cast_code integer conversion,
642
- to always convert values to integer calling #to_i. Fixes #7509.
804
+ * PostgreSQL inet and cidr types are converted to `IPAddr` objects.
643
805
 
644
- *Thiago Pradi*
806
+ *Dan McClain*
645
807
 
646
- * Fix time column type casting for invalid time string values to correctly return nil.
808
+ * PostgreSQL array type support. Any datatype can be used to create an
809
+ array column, with full migration and schema dumper support.
647
810
 
648
- *Adam Meehan*
811
+ To declare an array column, use the following syntax:
812
+
813
+ create_table :table_with_arrays do |t|
814
+ t.integer :int_array, array: true
815
+ # integer[]
816
+ t.integer :int_array, array: true, length: 2
817
+ # smallint[]
818
+ t.string :string_array, array: true, length: 30
819
+ # char varying(30)[]
820
+ end
821
+
822
+ This respects any other migration detail (limits, defaults, etc).
823
+ Active Record will serialize and deserialize the array columns on
824
+ their way to and from the database.
825
+
826
+ One thing to note: PostgreSQL does not enforce any limits on the
827
+ number of elements, and any array can be multi-dimensional. Any
828
+ array that is multi-dimensional must be rectangular (each sub array
829
+ must have the same number of elements as its siblings).
830
+
831
+ If the `pg_array_parser` gem is available, it will be used when
832
+ parsing PostgreSQL's array representation.
833
+
834
+ *Dan McClain*
835
+
836
+ * Attribute predicate methods, such as `article.title?`, will now raise
837
+ `ActiveModel::MissingAttributeError` if the attribute being queried for
838
+ truthiness was not read from the database, instead of just returning `false`.
649
839
 
650
- * Fix `becomes` when using a configured `inheritance_column`.
840
+ *Ernie Miller*
841
+
842
+ * `ActiveRecord::SchemaDumper` uses Ruby 1.9 style hash, which means that the
843
+ schema.rb file will be generated using this new syntax from now on.
844
+
845
+ *Konstantin Shabanov*
846
+
847
+ * Map interval with precision to string datatype in PostgreSQL. Fixes #7518.
651
848
 
652
849
  *Yves Senn*
653
850
 
851
+ * Fix eagerly loading associations without primary keys. Fixes #4976.
852
+
853
+ *Kelley Reynolds*
854
+
855
+ * Rails now raise an exception when you're trying to run a migration that has an invalid
856
+ file name. Only lower case letters, numbers, and '_' are allowed in migration's file name.
857
+ Please see #7419 for more details.
858
+
859
+ *Jan Bernacki*
860
+
861
+ * Fix bug when calling `store_accessor` multiple times.
862
+ Fixes #7532.
863
+
864
+ *Matt Jones*
865
+
866
+ * Fix store attributes that show the changes incorrectly.
867
+ Fixes #7532.
868
+
869
+ *Matt Jones*
870
+
871
+ * Fix `ActiveRecord::Relation#pluck` when columns or tables are reserved words.
872
+
873
+ *Ian Lesperance*
874
+
875
+ * Allow JSON columns to be created in PostgreSQL and properly encoded/decoded.
876
+ to/from database.
877
+
878
+ *Dickson S. Guedes*
879
+
880
+ * Fix time column type casting for invalid time string values to correctly return `nil`.
881
+
882
+ *Adam Meehan*
883
+
884
+ * Allow to pass Symbol or Proc into `:limit` option of #accepts_nested_attributes_for.
885
+
886
+ *Mikhail Dieterle*
887
+
888
+ * ActiveRecord::SessionStore has been extracted from Active Record as `activerecord-session_store`
889
+ gem. Please read the `README.md` file on the gem for the usage.
890
+
891
+ *Prem Sichanugrist*
892
+
654
893
  * Fix `reset_counters` when there are multiple `belongs_to` association with the
655
894
  same foreign key and one of them have a counter cache.
656
895
  Fixes #5200.
657
896
 
658
897
  *Dave Desrochers*
659
898
 
899
+ * `serialized_attributes` and `_attr_readonly` become class method only. Instance reader methods are deprecated.
900
+
901
+ *kennyj*
902
+
660
903
  * Round usec when comparing timestamp attributes in the dirty tracking.
661
904
  Fixes #6975.
662
905
 
663
906
  *kennyj*
664
907
 
665
- * Use inversed parent for first and last child of has_many association.
908
+ * Use inversed parent for first and last child of `has_many` association.
666
909
 
667
910
  *Ravil Bayramgalin*
668
911
 
669
- * Fix Column.microseconds and Column.fast_string_to_date to avoid converting
912
+ * Fix `Column.microseconds` and `Column.fast_string_to_time` to avoid converting
670
913
  timestamp seconds to a float, since it occasionally results in inaccuracies
671
914
  with microsecond-precision times. Fixes #7352.
672
915
 
673
916
  *Ari Pollak*
674
917
 
675
- * Fix `increment!`, `decrement!`, `toggle!` that was skipping callbacks.
676
- Fixes #7306.
918
+ * Fix AR#dup to nullify the validation errors in the dup'ed object. Previously the original
919
+ and the dup'ed object shared the same errors.
677
920
 
678
- *Rafael Mendonça França*
921
+ *Christian Seiler*
922
+
923
+ * Raise `ArgumentError` if list of attributes to change is empty in `update_all`.
924
+
925
+ *Roman Shatsov*
679
926
 
680
927
  * Fix AR#create to return an unsaved record when AR::RecordInvalid is
681
928
  raised. Fixes #3217.
682
929
 
683
930
  *Dave Yeu*
684
931
 
685
- * Remove unnecessary transaction when assigning has_one associations with a nil or equal value.
686
- Fix #7191.
932
+ * Fixed table name prefix that is generated in engines for namespaced models.
687
933
 
688
- *kennyj*
934
+ *Wojciech Wnętrzak*
689
935
 
690
- * Allow store to work with an empty column.
691
- Fix #4840.
936
+ * Make sure `:environment` task is executed before `db:schema:load` or `db:structure:load`.
937
+ Fixes #4772.
692
938
 
693
- *Jeremy Walker*
939
+ *Seamus Abshere*
694
940
 
695
- * Remove prepared statement from system query in postgresql adapter.
696
- Fix #5872.
941
+ * Allow Relation#merge to take a proc.
697
942
 
698
- *Ivan Evtuhovich*
943
+ This was requested by DHH to allow creating of one's own custom
944
+ association macros.
699
945
 
700
- * Make sure `:environment` task is executed before `db:schema:load` or `db:structure:load`
701
- Fixes #4772.
946
+ For example:
702
947
 
703
- *Seamus Abshere*
948
+ module Commentable
949
+ def has_many_comments(extra)
950
+ has_many :comments, -> { where(:foo).merge(extra) }
951
+ end
952
+ end
953
+
954
+ class Post < ActiveRecord::Base
955
+ extend Commentable
956
+ has_many_comments -> { where(:bar) }
957
+ end
704
958
 
959
+ *Jon Leighton*
705
960
 
706
- ## Rails 3.2.8 (Aug 9, 2012) ##
961
+ * Add CollectionProxy#scope.
707
962
 
708
- * Do not consider the numeric attribute as changed if the old value is zero and the new value
709
- is not a string.
710
- Fixes #7237.
963
+ This can be used to get a Relation from an association.
711
964
 
712
- *Rafael Mendonça França*
965
+ Previously we had a #scoped method, but we're deprecating that for
966
+ AR::Base, so it doesn't make sense to have it here.
713
967
 
714
- * Removes the deprecation of `update_attribute`. *fxn*
968
+ This was requested by DHH, to facilitate code like this:
715
969
 
716
- * Reverted the deprecation of `composed_of`. *Rafael Mendonça França*
970
+ Project.scope.order('created_at DESC').page(current_page).tagged_with(@tag).limit(5).scoping do
971
+ @topics = @project.topics.scope
972
+ @todolists = @project.todolists.scope
973
+ @attachments = @project.attachments.scope
974
+ @documents = @project.documents.scope
975
+ end
717
976
 
718
- * Reverted the deprecation of `*_sql` association options. They will
719
- be deprecated in 4.0 instead. *Jon Leighton*
977
+ *Jon Leighton*
720
978
 
721
- * Do not eager load AR session store. ActiveRecord::SessionStore depends on the abstract store
722
- in Action Pack. Eager loading this class would break client code that eager loads Active Record
723
- standalone.
724
- Fixes #7160
979
+ * Add `Relation#load`.
725
980
 
726
- *Xavier Noria*
981
+ This method explicitly loads the records and then returns `self`.
727
982
 
728
- * Do not set RAILS_ENV to "development" when using `db:test:prepare` and related rake tasks.
729
- This was causing the truncation of the development database data when using RSpec.
730
- Fixes #7175.
983
+ Rather than deciding between "do I want an array or a relation?",
984
+ most people are actually asking themselves "do I want to eager load
985
+ or lazy load?" Therefore, this method provides a way to explicitly
986
+ eager-load without having to switch from a `Relation` to an array.
731
987
 
732
- *Rafael Mendonça França*
988
+ Example:
989
+
990
+ @posts = Post.where(published: true).load
733
991
 
734
- ## Rails 3.2.7 (Jul 26, 2012) ##
992
+ *Jon Leighton*
993
+
994
+ * `Relation#order`: make new order prepend old one.
995
+
996
+ User.order("name asc").order("created_at desc")
997
+ # SELECT * FROM users ORDER BY created_at desc, name asc
998
+
999
+ This also affects order defined in `default_scope` or any kind of associations.
1000
+
1001
+ *Bogdan Gusiev*
1002
+
1003
+ * `Model.all` now returns an `ActiveRecord::Relation`, rather than an
1004
+ array of records. Use `Relation#to_a` if you really want an array.
1005
+
1006
+ In some specific cases, this may cause breakage when upgrading.
1007
+ However in most cases the `ActiveRecord::Relation` will just act as a
1008
+ lazy-loaded array and there will be no problems.
1009
+
1010
+ Note that calling `Model.all` with options (e.g.
1011
+ `Model.all(conditions: '...')` was already deprecated, but it will
1012
+ still return an array in order to make the transition easier.
1013
+
1014
+ `Model.scoped` is deprecated in favour of `Model.all`.
1015
+
1016
+ `Relation#all` still returns an array, but is deprecated (since it
1017
+ would serve no purpose if we made it return a `Relation`).
1018
+
1019
+ *Jon Leighton*
735
1020
 
736
1021
  * `:finder_sql` and `:counter_sql` options on collection associations
737
1022
  are deprecated. Please transition to using scopes.
@@ -740,281 +1025,477 @@
740
1025
 
741
1026
  * `:insert_sql` and `:delete_sql` options on `has_and_belongs_to_many`
742
1027
  associations are deprecated. Please transition to using `has_many
743
- :through`
1028
+ :through`.
744
1029
 
745
1030
  *Jon Leighton*
746
1031
 
747
- * `composed_of` has been deprecated. You'll have to write your own accessor
748
- and mutator methods if you'd like to use value objects to represent some
749
- portion of your models.
1032
+ * Added `#update_columns` method which updates the attributes from
1033
+ the passed-in hash without calling save, hence skipping validations and
1034
+ callbacks. `ActiveRecordError` will be raised when called on new objects
1035
+ or when at least one of the attributes is marked as read only.
750
1036
 
751
- *Steve Klabnik*
1037
+ post.attributes # => {"id"=>2, "title"=>"My title", "body"=>"My content", "author"=>"Peter"}
1038
+ post.update_columns(title: 'New title', author: 'Sebastian') # => true
1039
+ post.attributes # => {"id"=>2, "title"=>"New title", "body"=>"My content", "author"=>"Sebastian"}
752
1040
 
753
- * `update_attribute` has been deprecated. Use `update_column` if
754
- you want to bypass mass-assignment protection, validations, callbacks,
755
- and touching of updated_at. Otherwise please use `update_attributes`.
1041
+ *Sebastian Martinez + Rafael Mendonça França*
756
1042
 
757
- *Steve Klabnik*
1043
+ * The migration generator now creates a join table with (commented) indexes every time
1044
+ the migration name contains the word `join_table`:
758
1045
 
759
- ## Rails 3.2.6 (Jun 12, 2012) ##
1046
+ rails g migration create_join_table_for_artists_and_musics artist_id:index music_id
760
1047
 
761
- * protect against the nesting of hashes changing the
762
- table context in the next call to build_from_hash. This fix
763
- covers this case as well.
1048
+ *Aleksey Magusev*
764
1049
 
765
- CVE-2012-2695
1050
+ * Add `add_reference` and `remove_reference` schema statements. Aliases, `add_belongs_to`
1051
+ and `remove_belongs_to` are acceptable. References are reversible.
766
1052
 
767
- * Revert earlier 'perf fix' (see 3.2.4 changelog / GH #6289). This
768
- change introduced a regression (GH #6609). assoc.clear and
769
- assoc.delete_all have loaded the association before doing the delete
770
- since at least Rails 2.3. Doing the delete without loading the
771
- records means that the `before_remove` and `after_remove` callbacks do
772
- not get invoked. Therefore, this change was less a fix a more an
773
- optimisation, which should only have gone into master.
1053
+ Examples:
774
1054
 
775
- *Jon Leighton*
1055
+ # Create a user_id column
1056
+ add_reference(:products, :user)
1057
+ # Create a supplier_id, supplier_type columns and appropriate index
1058
+ add_reference(:products, :supplier, polymorphic: true, index: true)
1059
+ # Remove polymorphic reference
1060
+ remove_reference(:products, :supplier, polymorphic: true)
776
1061
 
777
- ## Rails 3.2.5 (Jun 1, 2012) ##
1062
+ *Aleksey Magusev*
778
1063
 
779
- * Restore behavior of Active Record 3.2.3 scopes.
780
- A series of commits relating to preloading and scopes caused a regression.
1064
+ * Add `:default` and `:null` options to `column_exists?`.
781
1065
 
782
- *Andrew White*
1066
+ column_exists?(:testings, :taggable_id, :integer, null: false)
1067
+ column_exists?(:testings, :taggable_type, :string, default: 'Photo')
783
1068
 
1069
+ *Aleksey Magusev*
784
1070
 
785
- ## Rails 3.2.4 (May 31, 2012) ##
1071
+ * `ActiveRecord::Relation#inspect` now makes it clear that you are
1072
+ dealing with a `Relation` object rather than an array:.
786
1073
 
787
- * Perf fix: Don't load the records when doing assoc.delete_all.
788
- GH #6289. *Jon Leighton*
1074
+ User.where(age: 30).inspect
1075
+ # => <ActiveRecord::Relation [#<User ...>, #<User ...>, ...]>
789
1076
 
790
- * Association preloading shouldn't be affected by the current scoping.
791
- This could cause infinite recursion and potentially other problems.
792
- See GH #5667. *Jon Leighton*
1077
+ User.where(age: 30).to_a.inspect
1078
+ # => [#<User ...>, #<User ...>]
793
1079
 
794
- * Datetime attributes are forced to be changed. GH #3965
1080
+ The number of records displayed will be limited to 10.
795
1081
 
796
- * Fix attribute casting. GH #5549
1082
+ *Brian Cardarella, Jon Leighton & Damien Mathieu*
797
1083
 
798
- * Fix #5667. Preloading should ignore scoping.
1084
+ * Add `collation` and `ctype` support to PostgreSQL. These are available for PostgreSQL 8.4 or later.
1085
+ Example:
799
1086
 
800
- * Predicate builder should not recurse for determining where columns.
801
- Thanks to Ben Murphy for reporting this! CVE-2012-2661
1087
+ development:
1088
+ adapter: postgresql
1089
+ host: localhost
1090
+ database: rails_development
1091
+ username: foo
1092
+ password: bar
1093
+ encoding: UTF8
1094
+ collation: ja_JP.UTF8
1095
+ ctype: ja_JP.UTF8
802
1096
 
1097
+ *kennyj*
803
1098
 
804
- ## Rails 3.2.3 (March 30, 2012) ##
1099
+ * Changed `validates_presence_of` on an association so that children objects
1100
+ do not validate as being present if they are marked for destruction. This
1101
+ prevents you from saving the parent successfully and thus putting the parent
1102
+ in an invalid state.
805
1103
 
806
- * Added find_or_create_by_{attribute}! dynamic method. *Andrew White*
1104
+ *Nick Monje & Brent Wheeldon*
807
1105
 
808
- * Whitelist all attribute assignment by default. Change the default for newly generated applications to whitelist all attribute assignment. Also update the generated model classes so users are reminded of the importance of attr_accessible. *NZKoz*
1106
+ * `FinderMethods#exists?` now returns `false` with the `false` argument.
809
1107
 
810
- * Update ActiveRecord::AttributeMethods#attribute_present? to return false for empty strings. *Jacobkg*
1108
+ *Egor Lynko*
811
1109
 
812
- * Fix associations when using per class databases. *larskanis*
1110
+ * Added support for specifying the precision of a timestamp in the postgresql
1111
+ adapter. So, instead of having to incorrectly specify the precision using the
1112
+ `:limit` option, you may use `:precision`, as intended. For example, in a migration:
813
1113
 
814
- * Revert setting NOT NULL constraints in add_timestamps *fxn*
1114
+ def change
1115
+ create_table :foobars do |t|
1116
+ t.timestamps precision: 0
1117
+ end
1118
+ end
815
1119
 
816
- * Fix mysql to use proper text types. Fixes #3931. *kennyj*
1120
+ *Tony Schneider*
817
1121
 
818
- * Fix #5069 - Protect foreign key from mass assignment through association builder. *byroot*
1122
+ * Allow `ActiveRecord::Relation#pluck` to accept multiple columns. Returns an
1123
+ array of arrays containing the typecasted values:
819
1124
 
1125
+ Person.pluck(:id, :name)
1126
+ # SELECT people.id, people.name FROM people
1127
+ # [[1, 'David'], [2, 'Jeremy'], [3, 'Jose']]
820
1128
 
821
- ## Rails 3.2.2 (March 1, 2012) ##
1129
+ *Jeroen van Ingen & Carlos Antonio da Silva*
822
1130
 
823
- * No changes.
1131
+ * Improve the derivation of HABTM join table name to take account of nesting.
1132
+ It now takes the table names of the two models, sorts them lexically and
1133
+ then joins them, stripping any common prefix from the second table name.
824
1134
 
1135
+ Some examples:
825
1136
 
826
- ## Rails 3.2.1 (January 26, 2012) ##
1137
+ Top level models (Category <=> Product)
1138
+ Old: categories_products
1139
+ New: categories_products
827
1140
 
828
- * The threshold for auto EXPLAIN is ignored if there's no logger. *fxn*
1141
+ Top level models with a global table_name_prefix (Category <=> Product)
1142
+ Old: site_categories_products
1143
+ New: site_categories_products
829
1144
 
830
- * Call `to_s` on the value passed to `table_name=`, in particular symbols
831
- are supported (regression). *Sergey Nartimov*
1145
+ Nested models in a module without a table_name_prefix method (Admin::Category <=> Admin::Product)
1146
+ Old: categories_products
1147
+ New: categories_products
832
1148
 
833
- * Fix possible race condition when two threads try to define attribute
834
- methods for the same class. *Jon Leighton*
1149
+ Nested models in a module with a table_name_prefix method (Admin::Category <=> Admin::Product)
1150
+ Old: categories_products
1151
+ New: admin_categories_products
835
1152
 
1153
+ Nested models in a parent model (Catalog::Category <=> Catalog::Product)
1154
+ Old: categories_products
1155
+ New: catalog_categories_products
836
1156
 
837
- ## Rails 3.2.0 (January 20, 2012) ##
1157
+ Nested models in different parent models (Catalog::Category <=> Content::Page)
1158
+ Old: categories_pages
1159
+ New: catalog_categories_content_pages
838
1160
 
839
- * Added a `with_lock` method to ActiveRecord objects, which starts
840
- a transaction, locks the object (pessimistically) and yields to the block.
841
- The method takes one (optional) parameter and passes it to `lock!`.
1161
+ *Andrew White*
842
1162
 
843
- Before:
1163
+ * Move HABTM validity checks to `ActiveRecord::Reflection`. One side effect of
1164
+ this is to move when the exceptions are raised from the point of declaration
1165
+ to when the association is built. This is consistant with other association
1166
+ validity checks.
844
1167
 
845
- class Order < ActiveRecord::Base
846
- def cancel!
847
- transaction do
848
- lock!
849
- # ... cancelling logic
850
- end
851
- end
852
- end
1168
+ *Andrew White*
853
1169
 
854
- After:
1170
+ * Added `stored_attributes` hash which contains the attributes stored using
1171
+ `ActiveRecord::Store`. This allows you to retrieve the list of attributes
1172
+ you've defined.
855
1173
 
856
- class Order < ActiveRecord::Base
857
- def cancel!
858
- with_lock do
859
- # ... cancelling logic
860
- end
861
- end
862
- end
1174
+ class User < ActiveRecord::Base
1175
+ store :settings, accessors: [:color, :homepage]
1176
+ end
863
1177
 
864
- *Olek Janiszewski*
1178
+ User.stored_attributes[:settings] # [:color, :homepage]
865
1179
 
866
- * 'on' and 'ON' boolean columns values are type casted to true
867
- *Santiago Pastorino*
1180
+ *Joost Baaij & Carlos Antonio da Silva*
868
1181
 
869
- * Added ability to run migrations only for given scope, which allows
870
- to run migrations only from one engine (for example to revert changes
871
- from engine that you want to remove).
1182
+ * PostgreSQL default log level is now 'warning', to bypass the noisy notice
1183
+ messages. You can change the log level using the `min_messages` option
1184
+ available in your config/database.yml.
872
1185
 
873
- Example:
874
- rake db:migrate SCOPE=blog
1186
+ *kennyj*
875
1187
 
876
- *Piotr Sarnacki*
1188
+ * Add uuid datatype support to PostgreSQL adapter.
877
1189
 
878
- * Migrations copied from engines are now scoped with engine's name,
879
- for example 01_create_posts.blog.rb. *Piotr Sarnacki*
1190
+ *Konstantin Shabanov*
880
1191
 
881
- * Implements `AR::Base.silence_auto_explain`. This method allows the user to
882
- selectively disable automatic EXPLAINs within a block. *fxn*
1192
+ * Added `ActiveRecord::Migration.check_pending!` that raises an error if
1193
+ migrations are pending.
883
1194
 
884
- * Implements automatic EXPLAIN logging for slow queries.
1195
+ *Richard Schneeman*
885
1196
 
886
- A new configuration parameter `config.active_record.auto_explain_threshold_in_seconds`
887
- determines what's to be considered a slow query. Setting that to `nil` disables
888
- this feature. Defaults are 0.5 in development mode, and `nil` in test and production
889
- modes.
1197
+ * Added `#destroy!` which acts like `#destroy` but will raise an
1198
+ `ActiveRecord::RecordNotDestroyed` exception instead of returning `false`.
890
1199
 
891
- As of this writing there's support for SQLite, MySQL (mysql2 adapter), and
892
- PostgreSQL.
1200
+ *Marc-André Lafortune*
893
1201
 
894
- *fxn*
1202
+ * Added support to `CollectionAssociation#delete` for passing `fixnum`
1203
+ or `string` values as record ids. This finds the records responding
1204
+ to the `id` and executes delete on them.
895
1205
 
896
- * Implemented ActiveRecord::Relation#pluck method
1206
+ class Person < ActiveRecord::Base
1207
+ has_many :pets
1208
+ end
897
1209
 
898
- Method returns Array of column value from table under ActiveRecord model
1210
+ person.pets.delete("1") # => [#<Pet id: 1>]
1211
+ person.pets.delete(2, 3) # => [#<Pet id: 2>, #<Pet id: 3>]
899
1212
 
900
- Client.pluck(:id)
1213
+ *Francesco Rodriguez*
901
1214
 
902
- *Bogdan Gusiev*
1215
+ * Deprecated most of the 'dynamic finder' methods. All dynamic methods
1216
+ except for `find_by_...` and `find_by_...!` are deprecated. Here's
1217
+ how you can rewrite the code:
903
1218
 
904
- * Automatic closure of connections in threads is deprecated. For example
905
- the following code is deprecated:
1219
+ * `find_all_by_...` can be rewritten using `where(...)`
1220
+ * `find_last_by_...` can be rewritten using `where(...).last`
1221
+ * `scoped_by_...` can be rewritten using `where(...)`
1222
+ * `find_or_initialize_by_...` can be rewritten using
1223
+ `where(...).first_or_initialize`
1224
+ * `find_or_create_by_...` can be rewritten using
1225
+ `find_or_create_by(...)` or where(...).first_or_create`
1226
+ * `find_or_create_by_...!` can be rewritten using
1227
+ `find_or_create_by!(...) or `where(...).first_or_create!`
906
1228
 
907
- Thread.new { Post.find(1) }.join
1229
+ The implementation of the deprecated dynamic finders has been moved
1230
+ to the `activerecord-deprecated_finders` gem. See below for details.
908
1231
 
909
- It should be changed to close the database connection at the end of
910
- the thread:
1232
+ *Jon Leighton*
911
1233
 
912
- Thread.new {
913
- Post.find(1)
914
- Post.connection.close
915
- }.join
1234
+ * Deprecated the old-style hash based finder API. This means that
1235
+ methods which previously accepted "finder options" no longer do. For
1236
+ example this:
916
1237
 
917
- Only people who spawn threads in their application code need to worry
918
- about this change.
1238
+ Post.find(:all, conditions: { comments_count: 10 }, limit: 5)
919
1239
 
920
- * Deprecated:
1240
+ Should be rewritten in the new style which has existed since Rails 3:
921
1241
 
922
- * `set_table_name`
923
- * `set_inheritance_column`
924
- * `set_sequence_name`
925
- * `set_primary_key`
926
- * `set_locking_column`
1242
+ Post.where(comments_count: 10).limit(5)
927
1243
 
928
- Use an assignment method instead. For example, instead of `set_table_name`, use `self.table_name=`:
1244
+ Note that as an interim step, it is possible to rewrite the above as:
929
1245
 
930
- class Project < ActiveRecord::Base
931
- self.table_name = "project"
932
- end
1246
+ Post.all.merge(where: { comments_count: 10 }, limit: 5)
933
1247
 
934
- Or define your own `self.table_name` method:
1248
+ This could save you a lot of work if there is a lot of old-style
1249
+ finder usage in your application.
935
1250
 
936
- class Post < ActiveRecord::Base
937
- def self.table_name
938
- "special_" + super
939
- end
940
- end
941
- Post.table_name # => "special_posts"
1251
+ `Relation#merge` now accepts a hash of
1252
+ options, but they must be identical to the names of the equivalent
1253
+ finder method. These are mostly identical to the old-style finder
1254
+ option names, except in the following cases:
1255
+
1256
+ * `:conditions` becomes `:where`.
1257
+ * `:include` becomes `:includes`.
1258
+
1259
+ The code to implement the deprecated features has been moved out to the
1260
+ `activerecord-deprecated_finders` gem. This gem is a dependency of Active
1261
+ Record in Rails 4.0, so the interface works out of the box. It will no
1262
+ longer be a dependency from Rails 4.1 (you'll need to add it to the
1263
+ `Gemfile` in 4.1), and will be maintained until Rails 5.0.
942
1264
 
943
1265
  *Jon Leighton*
944
1266
 
945
- * Generated association methods are created within a separate module to allow overriding and
946
- composition using `super`. For a class named `MyModel`, the module is named
947
- `MyModel::GeneratedFeatureMethods`. It is included into the model class immediately after
948
- the `generated_attributes_methods` module defined in ActiveModel, so association methods
949
- override attribute methods of the same name. *Josh Susser*
1267
+ * It's not possible anymore to destroy a model marked as read only.
950
1268
 
951
- * Implemented ActiveRecord::Relation#explain. *fxn*
1269
+ *Johannes Barre*
952
1270
 
953
- * Add ActiveRecord::Relation#uniq for generating unique queries.
1271
+ * Added ability to ActiveRecord::Relation#from to accept other ActiveRecord::Relation objects.
954
1272
 
955
- Before:
1273
+ Record.from(subquery)
1274
+ Record.from(subquery, :a)
956
1275
 
957
- Client.select('DISTINCT name')
1276
+ *Radoslav Stankov*
958
1277
 
959
- After:
1278
+ * Added custom coders support for ActiveRecord::Store. Now you can set
1279
+ your custom coder like this:
1280
+
1281
+ store :settings, accessors: [ :color, :homepage ], coder: JSON
1282
+
1283
+ *Andrey Voronkov*
960
1284
 
961
- Client.select(:name).uniq
1285
+ * `mysql` and `mysql2` connections will set `SQL_MODE=STRICT_ALL_TABLES` by
1286
+ default to avoid silent data loss. This can be disabled by specifying
1287
+ `strict: false` in your `database.yml`.
962
1288
 
963
- This also allows you to revert the unqueness in a relation:
1289
+ *Michael Pearson*
964
1290
 
965
- Client.select(:name).uniq.uniq(false)
1291
+ * Added default order to `first` to assure consistent results among
1292
+ different database engines. Introduced `take` as a replacement to
1293
+ the old behavior of `first`.
1294
+
1295
+ *Marcelo Silveira*
1296
+
1297
+ * Added an `:index` option to automatically create indexes for references
1298
+ and belongs_to statements in migrations.
1299
+
1300
+ The `references` and `belongs_to` methods now support an `index`
1301
+ option that receives either a boolean value or an options hash
1302
+ that is identical to options available to the add_index method:
1303
+
1304
+ create_table :messages do |t|
1305
+ t.references :person, index: true
1306
+ end
1307
+
1308
+ Is the same as:
1309
+
1310
+ create_table :messages do |t|
1311
+ t.references :person
1312
+ end
1313
+ add_index :messages, :person_id
1314
+
1315
+ Generators have also been updated to use the new syntax.
1316
+
1317
+ *Joshua Wood*
1318
+
1319
+ * Added `#find_by` and `#find_by!` to mirror the functionality
1320
+ provided by dynamic finders in a way that allows dynamic input more
1321
+ easily:
1322
+
1323
+ Post.find_by name: 'Spartacus', rating: 4
1324
+ Post.find_by "published_at < ?", 2.weeks.ago
1325
+ Post.find_by! name: 'Spartacus'
966
1326
 
967
1327
  *Jon Leighton*
968
1328
 
969
- * Support index sort order in sqlite, mysql and postgres adapters. *Vlad Jebelev*
1329
+ * Added ActiveRecord::Base#slice to return a hash of the given methods with
1330
+ their names as keys and returned values as values.
1331
+
1332
+ *Guillermo Iguaran*
1333
+
1334
+ * Deprecate eager-evaluated scopes.
970
1335
 
971
- * Allow the :class_name option for associations to take a symbol (:Client) in addition to
972
- a string ('Client').
1336
+ Don't use this:
973
1337
 
974
- This is to avoid confusing newbies, and to be consistent with the fact that other options
975
- like :foreign_key already allow a symbol or a string.
1338
+ scope :red, where(color: 'red')
1339
+ default_scope where(color: 'red')
1340
+
1341
+ Use this:
1342
+
1343
+ scope :red, -> { where(color: 'red') }
1344
+ default_scope { where(color: 'red') }
1345
+
1346
+ The former has numerous issues. It is a common newbie gotcha to do
1347
+ the following:
1348
+
1349
+ scope :recent, where(published_at: Time.now - 2.weeks)
1350
+
1351
+ Or a more subtle variant:
1352
+
1353
+ scope :recent, -> { where(published_at: Time.now - 2.weeks) }
1354
+ scope :recent_red, recent.where(color: 'red')
1355
+
1356
+ Eager scopes are also very complex to implement within Active
1357
+ Record, and there are still bugs. For example, the following does
1358
+ not do what you expect:
1359
+
1360
+ scope :remove_conditions, except(:where)
1361
+ where(...).remove_conditions # => still has conditions
976
1362
 
977
1363
  *Jon Leighton*
978
1364
 
979
- * In development mode the db:drop task also drops the test database. For symmetry with
980
- the db:create task. *Dmitriy Kiriyenko*
1365
+ * Remove IdentityMap
981
1366
 
982
- * Added ActiveRecord::Base.store for declaring simple single-column key/value stores *DHH*
1367
+ IdentityMap has never graduated to be an "enabled-by-default" feature, due
1368
+ to some inconsistencies with associations, as described in this commit:
983
1369
 
984
- class User < ActiveRecord::Base
985
- store :settings, accessors: [ :color, :homepage ]
986
- end
1370
+ https://github.com/rails/rails/commit/302c912bf6bcd0fa200d964ec2dc4a44abe328a6
1371
+
1372
+ Hence the removal from the codebase, until such issues are fixed.
1373
+
1374
+ *Carlos Antonio da Silva*
1375
+
1376
+ * Added the schema cache dump feature.
1377
+
1378
+ `Schema cache dump` feature was implemetend. This feature can dump/load internal state of `SchemaCache` instance
1379
+ because we want to boot rails more quickly when we have many models.
1380
+
1381
+ Usage notes:
1382
+
1383
+ 1) execute rake task.
1384
+ RAILS_ENV=production bundle exec rake db:schema:cache:dump
1385
+ => generate db/schema_cache.dump
1386
+
1387
+ 2) add config.active_record.use_schema_cache_dump = true in config/production.rb. BTW, true is default.
1388
+
1389
+ 3) boot rails.
1390
+ RAILS_ENV=production bundle exec rails server
1391
+ => use db/schema_cache.dump
1392
+
1393
+ 4) If you remove clear dumped cache, execute rake task.
1394
+ RAILS_ENV=production bundle exec rake db:schema:cache:clear
1395
+ => remove db/schema_cache.dump
1396
+
1397
+ *kennyj*
1398
+
1399
+ * Added support for partial indices to PostgreSQL adapter.
1400
+
1401
+ The `add_index` method now supports a `where` option that receives a
1402
+ string with the partial index criteria.
1403
+
1404
+ add_index(:accounts, :code, where: 'active')
987
1405
 
988
- u = User.new(color: 'black', homepage: '37signals.com')
989
- u.color # Accessor stored attribute
990
- u.settings[:country] = 'Denmark' # Any attribute, even if not specified with an accessor
1406
+ Generates
991
1407
 
1408
+ CREATE INDEX index_accounts_on_code ON accounts(code) WHERE active
992
1409
 
993
- * MySQL: case-insensitive uniqueness validation avoids calling LOWER when
994
- the column already uses a case-insensitive collation. Fixes #561.
1410
+ *Marcelo Silveira*
995
1411
 
996
- *Joseph Palermo*
1412
+ * Implemented ActiveRecord::Relation#none method.
997
1413
 
998
- * Transactional fixtures enlist all active database connections. You can test
999
- models on different connections without disabling transactional fixtures.
1414
+ The `none` method returns a chainable relation with zero records
1415
+ (an instance of the NullRelation class).
1416
+
1417
+ Any subsequent condition chained to the returned relation will continue
1418
+ generating an empty relation and will not fire any query to the database.
1419
+
1420
+ *Juanjo Bazán*
1421
+
1422
+ * Added the `ActiveRecord::NullRelation` class implementing the null
1423
+ object pattern for the Relation class.
1424
+
1425
+ *Juanjo Bazán*
1426
+
1427
+ * Added new `dependent: :restrict_with_error` option. This will add
1428
+ an error to the model, rather than raising an exception.
1429
+
1430
+ The `:restrict` option is renamed to `:restrict_with_exception` to
1431
+ make this distinction explicit.
1432
+
1433
+ *Manoj Kumar & Jon Leighton*
1434
+
1435
+ * Added `create_join_table` migration helper to create HABTM join tables.
1436
+
1437
+ create_join_table :products, :categories
1438
+ # =>
1439
+ # create_table :categories_products, id: false do |td|
1440
+ # td.integer :product_id, null: false
1441
+ # td.integer :category_id, null: false
1442
+ # end
1443
+
1444
+ *Rafael Mendonça França*
1445
+
1446
+ * The primary key is always initialized in the @attributes hash to `nil` (unless
1447
+ another value has been specified).
1448
+
1449
+ *Aaron Paterson*
1450
+
1451
+ * In previous releases, the following would generate a single query with
1452
+ an `OUTER JOIN comments`, rather than two separate queries:
1453
+
1454
+ Post.includes(:comments)
1455
+ .where("comments.name = 'foo'")
1456
+
1457
+ This behaviour relies on matching SQL string, which is an inherently
1458
+ flawed idea unless we write an SQL parser, which we do not wish to
1459
+ do.
1460
+
1461
+ Therefore, it is now deprecated.
1462
+
1463
+ To avoid deprecation warnings and for future compatibility, you must
1464
+ explicitly state which tables you reference, when using SQL snippets:
1465
+
1466
+ Post.includes(:comments)
1467
+ .where("comments.name = 'foo'")
1468
+ .references(:comments)
1469
+
1470
+ Note that you do not need to explicitly specify references in the
1471
+ following cases, as they can be automatically inferred:
1472
+
1473
+ Post.includes(:comments).where(comments: { name: 'foo' })
1474
+ Post.includes(:comments).where('comments.name' => 'foo')
1475
+ Post.includes(:comments).order('comments.name')
1476
+
1477
+ You do not need to worry about this unless you are doing eager
1478
+ loading. Basically, don't worry unless you see a deprecation warning
1479
+ or (in future releases) an SQL error due to a missing JOIN.
1480
+
1481
+ *Jon Leighton*
1000
1482
 
1001
- *Jeremy Kemper*
1483
+ * Support for the `schema_info` table has been dropped. Please
1484
+ switch to `schema_migrations`.
1002
1485
 
1003
- * Add first_or_create, first_or_create!, first_or_initialize methods to Active Record. This is a
1004
- better approach over the old find_or_create_by dynamic methods because it's clearer which
1005
- arguments are used to find the record and which are used to create it:
1486
+ *Aaron Patterson*
1006
1487
 
1007
- User.where(:first_name => "Scarlett").first_or_create!(:last_name => "Johansson")
1488
+ * Connections *must* be closed at the end of a thread. If not, your
1489
+ connection pool can fill and an exception will be raised.
1008
1490
 
1009
- *Andrés Mejía*
1491
+ *Aaron Patterson*
1010
1492
 
1011
- * Fix nested attributes bug where _destroy parameter is taken into account
1012
- during :reject_if => :all_blank (fixes #2937)
1493
+ * PostgreSQL hstore records can be created.
1013
1494
 
1014
- *Aaron Christy*
1495
+ *Aaron Patterson*
1015
1496
 
1016
- * Add ActiveSupport::Cache::NullStore for use in development and testing.
1497
+ * PostgreSQL hstore types are automatically deserialized from the database.
1017
1498
 
1018
- *Brian Durand*
1499
+ *Aaron Patterson*
1019
1500
 
1020
- Please check [3-1-stable](https://github.com/rails/rails/blob/3-1-stable/activerecord/CHANGELOG.md) for previous changes.
1501
+ Please check [3-2-stable](https://github.com/rails/rails/blob/3-2-stable/activerecord/CHANGELOG.md) for previous changes.