aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/CHANGELOG.md
Commit message (Collapse)AuthorAgeFilesLines
* Made ActiveRecord consistently use ActiveRecord::Type (notIain Beeston2016-10-031-0/+4
| | | | | | | | ActiveModel::Type) Some code was previously referring to ActiveModel::Type::*. This could cause issues in the future if any of the ActiveRecord::Type classes were overridden in the future.
* Serialize JSON attribute value nil as SQL NULL, not JSON 'null'Trung Duc Tran2016-09-231-0/+4
| | | | | | Test: JSON attribute value nil can be used in where(attr: nil) Add changelog entry
* Return true if attribute is not changed for update_attributePrathamesh Sonpatki2016-09-231-0/+7
| | | | | | | | | | | | | | - If the attribute is not changed, then update_attribute does not run SQL query, this effectively means that no change was made to the attribute. - This change was made in https://github.com/rails/rails/commit/0fcd4cf5 to avoid a SQL call. - But the change resulted into `nil` being returned when there was no change in the attribute value. - This commit corrects the behavior to return true if there is no change in attribute value. This is same as previous behavior of Rails 4.2 plus benefit of no additional SQL call. - Fixes #26593.
* Always store errors details information with symbolsRafael Mendonça França2016-09-191-0/+15
| | | | | | | | | | | | | | | | | | When the association is autosaved we were storing the details with string keys. This was creating inconsistency with other details that are added using the `Errors#add` method. It was also inconsistent with the `Errors#messages` storage. To fix this inconsistency we are always storing with symbols. This will cause a small breaking change because in those cases the details could be accessed as strings keys but now it can not. The reason that we chose to do this breaking change is because `#details` should be considered a low level object like `#messages` is. Fix #26499. [Rafael Mendonça França + Marcus Vieira]
* Clear attribute changes after handling lockingJakob Skjerning2016-09-141-0/+7
| | | | | | | | | | | | | | | | | Without this the changes to the lock version column will stick around even after `touch` returns. Before: model.touch model.changes # => {"lock_version"=>[0, "1"]} After: model.touch model.changes # {}
* 5-0-backport: activerecord/mysql2: Avoid setting @connection to nil, just ↵Dylan Thacker-Smith2016-09-131-0/+5
| | | | | | | | | | close it (#26473) * activerecord/mysql2: Avoid setting @connection to nil, just close it Backport of https://github.com/rails/rails/pull/26434 * Add a CHANGELOG entry
* Attempt to maintain encoding for arrays of strings with PGSean Griffin2016-08-311-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | I still think that this is something that should be handled in the pg gem, but it's not going to end up happening there so we'll do it here instead. Once we bump to pg 0.19 we can pass the encoding to the `encode` method instead. This issue occurs because C has no concept of encoding (or strings, really). The bytes that we pass here when sending the value to the database will always be interpreted as whatever encoding the connection is currently configured to use. That means that roundtripping to the database will lose no information However, after assigning we round trip through our type system without hitting the database. The only way that we can do the "correct" thin here would be to actually give a reference to the connection to the array type and have it check the current value of the connection's encoding -- which I'm strongly opposed to. We could also pass in the encoding when it's constructed, but since that can change independently of the type I'm not a huge fan of that either. This feels like a reasonable middle ground, where if we have an array of strings we simply use the encoding of the string we're given. Fixes #26326.
* Ensure that inverse associations are set before running callbacksSean Griffin2016-08-311-0/+7
| | | | | | | | | | | | | | | | | If a parent association was accessed in an `after_find` or `after_initialize` callback, it would always end up loading the association, and then immediately overwriting the association we just loaded. If this occurred in a way that the parent's `current_scope` was set to eager load the child, this would result in an infinite loop and eventually overflow the stack. For records that are created with `.new`, we have a mechanism to perform an action before the callbacks are run. I've introduced the same code path for records created with `instantiate`, and updated all code which sets inverse instances on newly loaded associations to use this block instead. Fixes #26320.
* Don't unnecessarily load a belongs_to when saving.James Coleman2016-08-261-0/+5
| | | | | | | | Previously, if the the association was previously loaded and then the foreign key changed by itself, a #save call would trigger a load of the new associated record during autosave. This is unnecessary and the autosave code (in that case) didn't use the loaded record anyways.
* Remove the SchemaDumper options and change the default behaviorRafael Mendonça França2016-08-221-3/+1
| | | | | Now the schema dumper by default doesn't align the types and arguments in the ruby format anymore.
* Merge pull request #25675 from TimPetricola/schema-no-standardized-column-widthsRafael Mendonça França2016-08-191-0/+6
|\ | | | | | | Option not to line up column attributes in schema.rb
| * Option not to line up column types and attributes in schema.rbTim Petricola2016-08-171-3/+9
| |
* | Add chengelog entry to #25976Rafael Mendonça França2016-08-191-0/+7
| | | | | | | | [Rafael Mendonça França + Robin Dupret]
* | Merge pull request #26154 from ↵Rafael Mendonça França2016-08-191-0/+32
|\ \ | | | | | | | | | | | | | | | kamipo/remove_text_default_treated_as_empty_string Remove text default treated as an empty string in non-strict mode
| * | Remove text default treated as an empty string in non-strict modeRyuta Kamizono2016-08-191-0/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Strict mode controls how MySQL handles invalid or missing values in data-change statements such as INSERT or UPDATE. If strict mode is not in effect, MySQL inserts adjusted values for invalid or missing values and produces warnings. ```ruby def test_mysql_not_null_defaults_non_strict using_strict(false) do with_mysql_not_null_table do |klass| record = klass.new assert_nil record.non_null_integer assert_nil record.non_null_string assert_nil record.non_null_text assert_nil record.non_null_blob record.save! record.reload assert_equal 0, record.non_null_integer assert_equal "", record.non_null_string assert_equal "", record.non_null_text assert_equal "", record.non_null_blob end end end ``` It is inconsistent with other types that only text/blob defaults treated as an empty string. This commit fixes the inconsistency.
* | | Merge pull request #26089 from travisoneill/sqlite_rollback_fixRafael Mendonça França2016-08-191-3/+11
|\ \ \ | |/ / |/| | | | | Sqlite3 Migration Error Fixed (issue #26087)
| * | Added nil case handling to allow rollback migration in case oftravis.h.oneill@gmail.com2016-08-171-3/+11
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | invalid column type /activerecord/lib/active_record/connection_adapters /abstract/schema_definitions.rb:306 type = type.to_sym Changed to the following to handle nil case: type = type.to_sym if type Added regression test for this case: /activerecord/test/cases/migration_test.rb:554 if current_adapter?(:SQLite3Adapter) def test_allows_sqlite3_rollback_on_invalid_column_type Person.connection.create_table :something, force: true do |t| t.column :number, :integer t.column :name, :string t.column :foo, :bar end assert Person.connection.column_exists?(:something, :foo) assert_nothing_raised { Person.connection.remove_column :something, :foo, :bar } assert !Person.connection.column_exists?(:something, :foo) assert Person.connection.column_exists?(:something, :name) assert Person.connection.column_exists?(:something, :number) ensure Person.connection.drop_table :something, if_exists: true end end
* / Deprecate `sanitize_conditions`. Use `sanitize_sql` insteadRyuta Kamizono2016-08-181-0/+4
|/ | | | Because `sanitize_conditions` protected method is only used in one place.
* Fix count which would sometimes force a DISTINCTMaxime Lapointe2016-08-161-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | The current behaviour of checking if there is a LEFT OUTER JOIN arel node to detect if we are doing eager_loading is wrong. This problem wasn't frequent before as only some pretty specific cases would add a LEFT OUTER JOIN arel node. However, the recent new feature left_outer_joins also add this node and made this problem happen frequently. Since in the perform_calculation function, we don't have access to eager_loading information, I had to extract the logic for the distinct out to the calculate method. As I was in the file for left_outer_join tests, I fixed a few that had bugs and I replaced some that were really weak with something that will catch more issues. In relation tests, the first test I changed would have failed if it had validated the hash returned by count instead of just checking how many pairs were in it. This is because this merge of join currently transforms the join node into an outer join node, which then made count do a distinct. So before this change, the return was {1=>1, 4=>1, 5=>1}.
* When calling association.find RecordNotFound is now raised with the same ↵Michel Pigassou2016-08-131-0/+5
| | | | argument as when we do it in Record.find (primary_key, id and model).
* Pass over changelogs [ci skip]Vipul A M2016-08-101-2/+5
|
* Don't assume all hashes are from multiparameter assignment in `composed_of`Sean Griffin2016-08-051-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | So this bug is kinda funky. The code path is basically "if we weren't passed an instance of the class we compose to, and we have a converter, call that". Ignoring the hash case for a moment, everything after that was roughly intended to be the "else" clause, meaning that we are expected to have an instance of the class we compose to. Really, we should be blowing up in that case, as we can give a much better error message than what they user will likely get (e.g. `NameError: No method first for String` or something). Still, Ruby is duck typed, so if the object you're assigning responds to the same methods as the type you compose to, knock yourself out. The hash case was added in 36e9be8 to remove a bunch of special cased code from multiparameter assignment. I wrongly assumed that the only time we'd get a hash there is in that case. Multiparameter assignment will construct a very specific hash though, where the keys are integers, and we will have a set of keys covering `1..part.size` exactly. I'm pretty sure this could actually be passed around as an array, but that's a different story. Really I should convert this to something like `class MultiParameterAssignment < Hash; end`, which I might do soon. However for a change that I'm willing to backport to 4-2-stable, this is what I want to go with for the time being. Fixes #25978
* Add the TABLE_SCHEMA condition to the SELECT statement in table_comment (#25945)Takeshi AKIMA2016-07-271-0/+4
| | | [Rafael Mendonça França + Takeshi AKIMA]
* Whoops, forgot the changelog entry for the previous commitSean Griffin2016-07-251-0/+5
|
* Merge pull request #25849 from suginoy/fix_merge_in_scopeRafael Mendonça França2016-07-201-0/+4
|\ | | | | | | Fix the calling `merge` method at first in a scope
| * Fix the calling `merge` method at first in a scopesuginoy2016-07-191-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | Changing the order of method chaining `merge` and other query method such as `joins` should produce the same result. ```ruby class Topic < ApplicationRecord scope :safe_chaininig, -> { joins(:comments).merge(Comment.newest) } scope :unsafe_chaininig, -> { merge(Comment.newest).joins(:comments) } #=> NoMethodError end ```
* | Fixes multiparameter attributes conversion with time_zone_aware_attributes ↵alpaca-tc2016-07-191-0/+4
|/ | | | and invalid params
* CHANGELOG for https://github.com/rails/rails/pull/25257 [ci skip]Prathamesh Sonpatki2016-07-171-2/+4
| | | | - Also minor weekly CHANGELOG cleanup.
* Add newline between each migration in `structure.sql`Grey Baker2016-07-141-0/+7
| | | | | | Keeps schema migration inserts as a single commit, so we still get all of the benefits of https://github.com/rails/rails/commit/42dd2336b31a8d98776d039a2b9fd7f834156a78, but allows for easier git diff-ing. Fixes #25504.
* adds support for limits in batch processingXavier Noria2016-07-131-0/+15
|
* Always prefer class types to query types when casting `group`Sean Griffin2016-07-111-0/+5
| | | | | | | | | | | | | When `group` is used in combination with any calculation method, the resulting hash uses the grouping expression as the key. Currently we're incorrectly always favoring the type reported by the query, instead of the type known by the class. This causes differing behavior depending on whether the adaptor actually gives proper types with the query or not. After this change, the behavior will be the same on all adaptors -- we see if we know the type from the class, fall back to the type from the query, and finally fall back to the identity type. Fixes #25595
* Cleanup CHANGELOGs [ci skip]Prathamesh Sonpatki2016-07-091-7/+7
| | | | | | - Cleanup Active Record CHANGELOG. - Add missing CHANGELOG for https://github.com/rails/rails/pull/25688. - Clarify that assets requests logging is suppressed.
* fix to_param to maximize contentRob Biedenharn2016-07-081-0/+11
| | | | | | | | | | | | | | | | | | | | | The documentation states that parameter values longer than 20 characters will be truncated by words, but the example shows that a parameter based on "David Heinemeier Hansson" (with id: 125) becomes "125-david" when "David Heinemeier".length == 16 so why so short? The answer lies in the use of the #truncate option omission: nil which seems to have been intended to mean "nothing", but which actually causes the default string "..." to be used. This causes #truncate to cleave words until the "..." can be added and still remain within the requested size of 20 characters. The better option is omission: '' (which is probably what was originally intended). Furthermore, since the use of #parameterize will remove non-alphanumeric characters, we can maximize the useful content of the output by calling parameterize first and then giving truncate a separator: /-/ rather than a space.
* Re-check that the connection is still stale before we reap itMatthew Draper2016-07-061-0/+7
| | | | | | | A concurrent thread may have also detected it to be stale, and already released (or even reassigned) it by now. Fixes #25585
* Do not specal case inspecting associated arrays of over 10 elements, ↵Kevin McPhillips2016-06-291-0/+6
| | | | preventing infinite looping in some cases.
* Remove unused `ActiveRecord::Base.connection_id`Sean Griffin2016-06-291-0/+5
| | | | | | | | This method appears to have been partially used in connection pool caching, but it was introduced without much reasoning or any tests. One edge case test was added later on, but it was focused on implementation details. This method is no longer used outside of tests, and as such is removed.
* Merge pull request #24773 from ralinc/fix-silent-fail-on-psql-commandArthur Nogueira Neves2016-06-161-0/+14
|\ | | | | PostgreSQL: Fix db:structure:load silent failure on SQL error
| * PostgreSQL: Fix db:structure:load silent failure on SQL errorRalin Chimev2016-05-101-0/+14
| | | | | | | | | | | | | | | | The command line flag "-v ON_ERROR_STOP=1" should be used when invoking psql to make sure errors are not suppressed. Example: psql -v ON_ERROR_STOP=1 -q -f awesome-file.sql my-app-db Fixes #23818.
* | Ensure hashes can be passed to attributes using `composed_of`Sean Griffin2016-05-311-0/+5
| | | | | | | | | | | | | | | | | | | | | | This behavior was broken by 36e9be85. When the value is assigned directly, either through mass assignment or directly assigning a hash, the hash gets passed through to this writer method directly. While this is intended to handle certain cases, when an explicit converter has been provided, we should continue to use that instead. The positioning of the added guard caused the new behavior to override that case. Fixes #25210
* | Merge pull request #25093 from Erol/activerecord-transaction-serialization-errorRafael França2016-05-211-0/+5
|\ \ | | | | | | Introduce AR::TransactionSerializationError for transaction serialization failures or deadlocks
| * | Add AR::TransactionSerializationError for transaction serialization failures ↵Erol Fornoles2016-05-211-0/+5
| | | | | | | | | | | | or deadlocks
* | | Whitespaces [ci skip]Rafael Mendonça França2016-05-211-0/+1
| | |
* | | Add CHANGELOG.md reference for #24958 (#25094)Jon Moss2016-05-211-0/+4
|/ / | | | | | | | | | | | | Sorry for forgetting to include it in my original PR :grimacing: r? @rafaelfranca [ci skip]
* | Merge pull request #23810 from xijo/fix_json_coder_when_mysql_strict_is_disabledSean Griffin2016-05-161-0/+4
|\ \ | |/ |/| | | Fix bug in JSON deserialization when column default is an empty string
| * Fix bug in JSON deserialization when column default is an empty stringJohannes Opper2016-02-221-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When `ActiveRecord::Coders::JSON` serialization is used and the default of the column returns `''` it raises the following error: ``` JSON::ParserError: A JSON text must at least contain two octets! ``` If MySQL is running in non-strict mode, it returns an empty string as column default for a text column: ```ruby def extract_default if blob_or_text_column? @default = null || strict ? nil : '' end end ``` Since `''` is invalid JSON, there shouldn't be an attempt to parse it, it should be treated like nil. ActiveRecord::Coders::JSON should behave consistently for all possible non-user-set column default values.
* | Start Rails 5.1 development :tada:Rafael Mendonça França2016-05-101-2114/+1
| |
* | Preparing for 5.0.0.rc1 releaseRafael Mendonça França2016-05-061-0/+5
| |
* | remove `empty?` from CHANGELOG [ci skip]yuuji.yaginuma2016-05-031-2/+1
| | | | | | | | Follow up to 98264a1343fad6bb6637893a37fd571916b4158c
* | Prep Rails 5 beta 4eileencodes2016-04-271-0/+2
| |
* | Add Expression Indexes and Operator Classes support for PostgreSQLRyuta Kamizono2016-04-241-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Example: create_table :users do |t| t.string :name t.index 'lower(name) varchar_pattern_ops' end Fixes #19090. Fixes #21765. Fixes #21819. Fixes #24359. Signed-off-by: Jeremy Daer <jeremydaer@gmail.com>