2020-12-10 15:37:22 +00:00
* Makes `ActiveRecord::AttributeMethods::Query` respect the getter overrides defined in the model.
Fixes #40771 .
Before:
```ruby
class User
def admin
false # Overriding the getter to always return false
end
end
user = User.first
user.update(admin: true)
user.admin # false (as expected, due to the getter overwrite)
user.admin? # true (not expected, returned the DB column value)
```
After this commit, `user.admin?` above returns false, as expected.
2020-12-18 06:06:16 +00:00
* Allow delegated_type to be specified primary_key and foreign_key.
Since delegated_type assumes that the foreign_key ends with `_id` ,
`singular_id` defined by it does not work when the foreign_key does
not end with `id` . This change fixes it by taking into account
`primary_key` and `foreign_key` in the options.
*Ryota Egusa*
2020-09-17 20:12:58 +00:00
* Expose an `invert_where` method that will invert all scope conditions.
```ruby
class User
scope :active, -> { where(accepted: true, locked: false) }
end
User.active
# ... WHERE `accepted` = 1 AND `locked` = 0
User.active.invert_where
# ... WHERE NOT (`accepted` = 1 AND `locked` = 0)
```
*Kevin Deisz*
allow passing false to :polymorphic option of belongs_to
before this, passing false would raise the following error
because a condition in AR would disregard the option entirely
if false was passed.
ArgumentError: Unknown key: :polymorphic. Valid keys are:
:class_name, :anonymous_class, :primary_key, :foreign_key,
:dependent, :validate, :inverse_of, :strict_loading, :autosave,
:required, :touch, :counter_cache, :optional, :default
2020-12-18 03:38:36 +00:00
* Restore possibility of passing `false` to :polymorphic option of `belongs_to` .
Previously, passing `false` would trigger the option validation logic
to throw an error saying :polymorphic would not be a valid option.
*glaszig*
2020-12-17 19:41:00 +00:00
* Remove deprecated `database` kwarg from `connected_to` .
*Eileen M. Uchitelle* , *John Crepezzi*
2020-12-11 15:52:00 +00:00
* Allow adding nonnamed expression indexes to be revertible.
Fixes #40732 .
Previously, the following code would raise an error, when executed while rolling back,
and the index name should be specified explicitly. Now, the index name is inferred
automatically.
```ruby
add_index(:items, "to_tsvector('english', description)")
```
*fatkodima*
2020-11-24 17:38:49 +00:00
* Only warn about negative enums if a positive form that would cause conflicts exists.
Fixes #39065 .
*Alex Ghiculescu*
2020-11-19 22:20:45 +00:00
* Add option to run `default_scope` on all queries.
Previously, a `default_scope` would only run on select or insert queries. In some cases, like non-Rails tenant sharding solutions, it may be desirable to run `default_scope` on all queries in order to ensure queries are including a foreign key for the shard (ie `blog_id` ).
Now applications can add an option to run on all queries including select, insert, delete, and update by adding an `all_queries` option to the default scope definition.
```ruby
class Article < ApplicationRecord
default_scope -> { where(blog_id: Current.blog.id) }, all_queries: true
end
```
*Eileen M. Uchitelle*
2020-11-26 13:15:18 +00:00
* Add `where.associated` to check for the presence of an association.
```ruby
# Before:
account.users.joins(:contact).where.not(contact_id: nil)
# After:
account.users.where.associated(:contact)
```
Also mirrors `where.missing` .
*Kasper Timm Hansen*
2020-08-07 19:36:22 +00:00
* Allow constructors (`build_association` and `create_association` ) on
`has_one :through` associations.
*Santiago Perez Perret*
2020-04-14 14:33:56 +00:00
2020-12-02 23:37:26 +00:00
Please check [6-1-stable ](https://github.com/rails/rails/blob/6-1-stable/activerecord/CHANGELOG.md ) for previous changes.