CHANGELOG.md 6.3 KB
Newer Older
1 2 3 4
*   Allow `ActiveRecord::Base.configurations=` to be set with a symbolized hash.

    *Gannon McGibbon*

5 6 7 8 9 10
*   Don't update counter cache unless the record is actually saved.

    Fixes #31493, #33113, #33117.

    *Ryuta Kamizono*

11 12 13 14
*   Deprecate `ActiveRecord::Result#to_hash` in favor of `ActiveRecord::Result#to_a`.

    *Gannon McGibbon*, *Kevin Cheng*

15
*   SQLite3 adapter supports expression indexes.
16 17 18 19 20 21 22 23 24 25 26

    ```
    create_table :users do |t|
      t.string :email
    end

    add_index :users, 'lower(email)', name: 'index_users_on_email', unique: true
    ```

    *Gray Kemmey*

27 28 29 30 31 32
*   Allow subclasses to redefine autosave callbacks for associated records.

    Fixes #33305.

    *Andrey Subbota*

Y
Yasuo Honda 已提交
33 34 35 36
*   Bump minimum MySQL version to 5.5.8.

    *Yasuo Honda*

37 38 39 40 41 42 43
*   Use MySQL utf8mb4 character set by default.

    `utf8mb4` character set with 4-Byte encoding supports supplementary characters including emoji.
    The previous default 3-Byte encoding character set `utf8` is not enough to support them.

    *Yasuo Honda*

D
Darwin D Wu 已提交
44 45 46 47
*   Fix duplicated record creation when using nested attributes with `create_with`.

    *Darwin Wu*

48 49 50 51
*   Configuration item `config.filter_parameters` could also filter out
    sensitive values of database columns when call `#inspect`.
    We also added `ActiveRecord::Base::filter_attributes`/`=` in order to
    specify sensitive attributes to specific model.
52 53 54

    ```
    Rails.application.config.filter_parameters += [:credit_card_number]
55 56 57
    Account.last.inspect # => #<Account id: 123, name: "DHH", credit_card_number: [FILTERED] ...>
    SecureAccount.filter_attributes += [:name]
    SecureAccount.last.inspect # => #<SecureAccount id: 42, name: [FILTERED], credit_card_number: [FILTERED] ...>
58 59 60 61
    ```

    *Zhang Kang*

62 63 64 65 66 67
*   Deprecate `column_name_length`, `table_name_length`, `columns_per_table`,
    `indexes_per_table`, `columns_per_multicolumn_index`, `sql_query_length`,
    and `joins_per_query` methods in `DatabaseLimits`.

    *Ryuta Kamizono*

R
Ryuta Kamizono 已提交
68
*   `ActiveRecord::Base.configurations` now returns an object.
69

R
Ryuta Kamizono 已提交
70
    `ActiveRecord::Base.configurations` used to return a hash, but this
71 72 73 74 75 76 77 78
    is an inflexible data model. In order to improve multiple-database
    handling in Rails, we've changed this to return an object. Some methods
    are provided to make the object behave hash-like in order to ease the
    transition process. Since most applications don't manipulate the hash
    we've decided to add backwards-compatible functionality that will throw
    a deprecation warning if used, however calling `ActiveRecord::Base.configurations`
    will use the new version internally and externally.

79
    For example, the following `database.yml`:
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103

    ```
    development:
      adapter: sqlite3
      database: db/development.sqlite3
    ```

    Used to become a hash:

    ```
    { "development" => { "adapter" => "sqlite3", "database" => "db/development.sqlite3" } }
    ```

    Is now converted into the following object:

    ```
    #<ActiveRecord::DatabaseConfigurations:0x00007fd1acbdf800 @configurations=[
      #<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbded10 @env_name="development",
        @spec_name="primary", @config={"adapter"=>"sqlite3", "database"=>"db/development.sqlite3"}>
      ]
    ```

    Iterating over the database configurations has also changed. Instead of
    calling hash methods on the `configurations` hash directly, a new method `configs_for` has
104 105 106 107
    been provided that allows you to select the correct configuration. `env_name`, and
    `spec_name` arguments are optional. For example these return an array of
    database config objects for the requested environment and a single database config object
    will be returned for the requested environment and specification name respectively.
108 109

    ```
110 111
    ActiveRecord::Base.configurations.configs_for(env_name: "development")
    ActiveRecord::Base.configurations.configs_for(env_name: "development", spec_name: "primary")
112 113 114 115
    ```

    *Eileen M. Uchitelle*, *Aaron Patterson*

116 117 118 119 120 121 122 123 124 125
*   Add database configuration to disable advisory locks.

    ```
    production:
      adapter: postgresql
      advisory_locks: false
    ```

    *Guo Xiang*

126 127 128 129
*   SQLite3 adapter `alter_table` method restores foreign keys.

    *Yasuo Honda*

B
bogdanvlviv 已提交
130 131 132 133 134 135 136 137
*   Allow `:to_table` option to `invert_remove_foreign_key`.

    Example:

       remove_foreign_key :accounts, to_table: :owners

    *Nikolay Epifanov*, *Rich Chen*

138 139 140 141 142
*   Add environment & load_config dependency to `bin/rake db:seed` to enable
    seed load in environments without Rails and custom DB configuration

    *Tobias Bielohlawek*

143
*   Fix default value for mysql time types with specified precision.
144 145 146

    *Nikolay Kondratyev*

147 148 149 150
*   Fix `touch` option to behave consistently with `Persistence#touch` method.

    *Ryuta Kamizono*

151 152 153 154 155
*   Migrations raise when duplicate column definition.

    Fixes #33024.

    *Federico Martinez*
R
Ryuta Kamizono 已提交
156

157 158 159 160
*   Bump minimum SQLite version to 3.8

    *Yasuo Honda*

161
*   Fix parent record should not get saved with duplicate children records.
162

163
    Fixes #32940.
164 165 166

    *Santosh Wadghule*

167 168 169 170
*   Fix logic on disabling commit callbacks so they are not called unexpectedly when errors occur.

    *Brian Durand*

171 172 173 174 175
*   Ensure `Associations::CollectionAssociation#size` and `Associations::CollectionAssociation#empty?`
    use loaded association ids if present.

    *Graham Turner*

176 177 178 179
*   Add support to preload associations of polymorphic associations when not all the records have the requested associations.

    *Dana Sherson*

180 181 182 183 184 185 186 187
*   Add `touch_all` method to `ActiveRecord::Relation`.

    Example:

        Person.where(name: "David").touch_all(time: Time.new(2020, 5, 16, 0, 0, 0))

    *fatkodima*, *duggiefresh*

188
*   Add `ActiveRecord::Base.base_class?` predicate.
189 190 191

    *Bogdan Gusiev*

192
*   Add custom prefix/suffix options to `ActiveRecord::Store.store_accessor`.
193

194
    *Tan Huynh*, *Yukio Mizuta*
195

J
Jeremy Daer 已提交
196 197 198 199
*   Rails 6 requires Ruby 2.4.1 or newer.

    *Jeremy Daer*

200 201 202
*   Deprecate `update_attributes`/`!` in favor of `update`/`!`.

    *Eddie Lebow*
203

R
Ryuta Kamizono 已提交
204 205
*   Add `ActiveRecord::Base.create_or_find_by`/`!` to deal with the SELECT/INSERT race condition in
    `ActiveRecord::Base.find_or_create_by`/`!` by leaning on unique constraints in the database.
206 207

    *DHH*
208

209 210 211 212
*   Add `Relation#pick` as short-hand for single-value plucks.

    *DHH*

213

214
Please check [5-2-stable](https://github.com/rails/rails/blob/5-2-stable/activerecord/CHANGELOG.md) for previous changes.