aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/CHANGELOG.md
Commit message (Collapse)AuthorAgeFilesLines
* Refactor AS::Callbacks halt config and fix the documentationRoque Pinel2015-10-011-1/+1
| | | | | | | | | Move from `AS::Callbacks::CallbackChain.halt_and_display_warning_on_return_false` to `AS::Callbacks.halt_and_display_warning_on_return_false` base on [this discussion](https://github.com/rails/rails/pull/21218#discussion_r39354580) Fix the documentation broken by 0a120a818d413c64ff9867125f0b03788fc306f8
* Merge pull request #20574 from repinel/fix-db-fixtures-loadYves Senn2015-09-301-0/+13
|\ | | | | | | | | | | | | Allow fixtures YAML files to set the model class in the file itself Conflicts: activerecord/CHANGELOG.md
| * Allow fixtures YAML files to set the model class in the file itselfRoque Pinel2015-09-111-0/+15
| | | | | | | | | | | | | | | | Currently, `set_fixture_class` is only available using the `TestFixtures` concern and it is ignored for `rake db:fixtures:load`. Using the correct model class, it is possible for the fixture load to also load the associations from the YAML files (e.g., `:belongs_to` and `:has_many`).
* | `validates_acceptance_of` shouldn't require a database connectionSean Griffin2015-09-251-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | The implementation of `attribute_method?` on Active Record requires establishing a database connection and querying the schema. As a general rule, we don't want to require database connections for any class macro, as the class should be able to be loaded without a database (e.g. for things like compiling assets). Instead of eagerly defining these methods, we do it lazily the first time they are accessed via `method_missing`. This should not cause any performance hits, as it will only hit `method_missing` once for the entire class.
* | Implement ActiveRecord::Base.ignored_columnsJean Boussier2015-09-241-0/+5
| |
* | Merge pull request #21550 from didacte/unscope-associationsSean Griffin2015-09-241-0/+4
|\| | | | | | | ActiveRecord: use association's `unscope` when preloading
* | Merge pull request #20317Sean Griffin2015-09-231-0/+20
|\ \ | | | | | | | | | | | | AR: take precision into count when assigning a value to timestamp attribute
| * | Fixed taking precision into count when assigning a value to timestamp attributeBogdan Gusiev2015-09-231-0/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Timestamp column can have less precision than ruby timestamp In result in how big a fraction of a second can be stored in the database. m = Model.create! m.created_at.usec == m.reload.created_at.usec # => false # due to different seconds precision in Time.now and database column If the precision is low enough, (mysql default is 0, so it is always low enough by default) the value changes when model is reloaded from the database. This patch fixes that issue ensuring that any timestamp assigned as an attribute is converted to column precision under the attribute.
* | | introduce `conn.data_source_exists?` and `conn.data_sources`.Yves Senn2015-09-221-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | These new methods are used from the Active Record model layer to determine which relations are viable to back a model. These new methods allow us to change `conn.tables` in the future to only return tables and no views. Same for `conn.table_exists?`. The goal is to provide the following introspection methods on the connection: * `tables` * `table_exists?` * `views` * `view_exists?` * `data_sources` (views + tables) * `data_source_exists?` (views + tables)
* | | Merge pull request #20569 from theSteveMitchell/masterYves Senn2015-09-221-0/+5
|\ \ \ | |/ / |/| / | |/ Check mysql structure_load for errors
* | Ensure aliased attributes passed to `select` are quoted if using `from`Sean Griffin2015-09-211-0/+6
| | | | | | | | | | | | Fixes #21488 [Sean Griffin & johanlunds]
* | Merge pull request #17696 from kamipo/unsigned_integer_supportJeremy Daer2015-09-191-0/+19
|\ \ | | | | | | | | | Add `unsigned` support for numeric data types in MySQL
| * | Add `unsigned` types for numeric data types in MySQLRyuta Kamizono2015-09-181-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In the case of using `unsigned` as the type: create_table :foos do |t| t.unsigned_integer :unsigned_integer t.unsigned_bigint :unsigned_bigint t.unsigned_float :unsigned_float t.unsigned_decimal :unsigned_decimal, precision: 10, scale: 2 end
| * | Add `unsigned` support for numeric data types in MySQLRyuta Kamizono2015-09-181-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Example: create_table :foos do |t| t.integer :unsigned_integer, unsigned: true t.bigint :unsigned_bigint, unsigned: true t.float :unsigned_float, unsigned: true t.decimal :unsigned_decimal, unsigned: true, precision: 10, scale: 2 end
* | | Merge pull request #21609 from kamipo/do_not_dump_view_as_tableJeremy Daer2015-09-191-0/+4
|\ \ \ | | | | | | | | | | | | Do not dump a view as a table in sqlite3, mysql and mysql2 adapters
| * | | Add `#views` and `#view_exists?` methods on connection adaptersRyuta Kamizono2015-09-131-0/+4
| | |/ | |/|
* | | Correctly dump composite primary keyRyuta Kamizono2015-09-201-0/+11
| |/ |/| | | | | | | | | | | | | | | Example: create_table :barcodes, primary_key: ["region", "code"] do |t| t.string :region t.integer :code end
* | Merge pull request #21581 from ronakjangir47/restrict_with_errorYves Senn2015-09-171-0/+5
|/ | | | `restrict_with_error` message will now respect owner’s human name
* Correct query for PostgreSQL 8.2Matthew Draper2015-09-081-0/+4
| | | | Generic cast-to-text was only added in 8.3.
* Merge pull request #21527 from rngtng/fix-migrator-path-setupYves Senn2015-09-071-0/+6
|\ | | | | | | Use global migrations_path configuration in Migrator
| * Allow global migrations_path configuration with using value from ↵Tobias Bielohlawek2015-09-071-0/+11
|/ | | | database_tasks instead of Migrator
* changelog, minor formatting changes.Yves Senn2015-09-071-9/+9
|
* Merge pull request #21317 from ↵Matthew Draper2015-09-071-0/+7
|\ | | | | | | | | | | greysteil/support-postgres-drop-index-concurrently Support dropping indexes concurrently in Postgres
| * Support dropping indexes concurrently in PostgresGrey Baker2015-09-051-0/+7
| | | | | | | | | | See http://www.postgresql.org/docs/9.4/static/sql-dropindex.html for more details.
* | Deprecate passing conditions to AR::Relation destroy_all and delete_all methodsWojciech Wnętrzak2015-09-061-0/+5
|/
* pg, `create_schema`, `drop_schema` and `rename_table` quote schema name.Yves Senn2015-08-281-0/+12
| | | | | | | | Closes #21418. Previously schema names were not quoted. This leads to issues when a schema names contains a ".". Methods in `schema_statements.rb` should quote user input.
* PostgreSQL, add `:if_exists` to `#drop_schema`.Yves Senn2015-08-281-0/+6
|
* Only nullify persisted has_one target associationsAgis-2015-08-241-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | Since after 87d1aba3c `dependent: :destroy` callbacks on has_one assocations run *after* destroy, it is possible that a nullification is attempted on an already destroyed target: class Car < ActiveRecord::Base has_one :engine, dependent: :nullify end class Engine < ActiveRecord::Base belongs_to :car, dependent: :destroy end > car = Car.create! > engine = Engine.create!(car: car) > engine.destroy! # => ActiveRecord::ActiveRecordError: cannot update a > destroyed record In the above case, `engine.destroy!` deletes `engine` and *then* triggers the deletion of `car`, which in turn triggers a nullification of `engine.car_id`. However, `engine` is already destroyed at that point. Fixes #21223.
* uniqueness validation raises error for persisted record without pk.Yves Senn2015-08-201-0/+7
| | | | | | | | Closes #21304. While we can validate uniqueness for record without primary key on creation, there is no way to exclude the current record when updating. (The update itself will need a primary key to work correctly).
* Add a native JSON data type support in MySQLRyuta Kamizono2015-08-181-0/+10
| | | | | | | | | | As of MySQL 5.7.8, MySQL supports a native JSON data type. Example: create_table :json_data_type do |t| t.json :settings end
* descriptive error message when fixtures contian a missing column.Yves Senn2015-08-131-0/+6
| | | | Closes #21201.
* Merge pull request #17885 from starbelly/patch-1Yves Senn2015-08-111-0/+5
|\ | | | | | | | | | | | | Add method to run command-line db apps Conflicts: activerecord/CHANGELOG.md
| * Add run_cmd class method to ActiveRecord::Tasks::DatabaseTasksstarbelly2015-08-011-0/+8
| | | | | | | | | | | | | | | | | | | | - Added run_cmd() class method to dry up Kernel.system() messages within this namespace and avoid shell expansion by passing a list of arguments instead of a string - Update structure_dump, structure_load, and related tests units to pass a list of params instead of using a string to avoid shell expansion
* | Remove XML Serialization from core.Zachary Scott2015-08-071-0/+4
| | | | | | | | | | | | | | This includes the following classes: - ActiveModel::Serializers::Xml - ActiveRecord::Serialization::XmlSerializer
* | Add ActiveRecord::Relation#in_batchesSina Siadat2015-08-071-0/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `in_batches` yields Relation objects if a block is given, otherwise it returns an instance of `BatchEnumerator`. The existing `find_each` and `find_in_batches` methods work with batches of records. The new API allows working with relation batches as well. Examples: Person.in_batches.each_record(&:party_all_night!) Person.in_batches.update_all(awesome: true) Person.in_batches.delete_all Person.in_batches.map do |relation| relation.delete_all sleep 10 # Throttles the delete queries end
* | Merge pull request #20459Sean Griffin2015-08-061-0/+15
|\ \
| * | Add missing data types for ActiveRecord migrationsMehmet Emin İNAÇ2015-06-081-0/+15
| | |
* | | Merge pull request #20884Sean Griffin2015-08-011-0/+10
|\ \ \ | |_|/ |/| | | | | Add #cache_key to ActiveRecord::Relation.
| * | Add #cache_key to ActiveRecord::Relation.Alberto F. Capel2015-07-201-0/+10
| | |
* | | minor AR changelog edits. [ci skip]Yves Senn2015-08-011-9/+8
| | |
* | | Properly allow uniqueness validations on primary keys.Sean Griffin2015-07-251-0/+6
| | | | | | | | | | | | | | | | | | This is an alternate implementation of #20966. [Sean Griffin & presskey]
* | | `destroy` shouldn't raise when child associations fail to saveSean Griffin2015-07-241-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Deep down in the association internals, we're calling `destroy!` rather than `destroy` when handling things like `dependent` or autosave association callbacks. Unfortunately, due to the structure of the code (e.g. it uses callbacks for everything), it's nearly impossible to pass whether to call `destroy` or `destroy!` down to where we actually need it. As such, we have to do some legwork to handle this. Since the callbacks are what actually raise the exception, we need to rescue it in `ActiveRecord::Callbacks`, rather than `ActiveRecord::Persistence` where it matters. (As an aside, if this code wasn't so callback heavy, it would handling this would likely be as simple as changing `destroy` to call `destroy!` instead of the other way around). Since we don't want to lose the exception when `destroy!` is called (in particular, we don't want the value of the `record` field to change to the parent class), we have to do some additional legwork to hold onto it where we can use it. Again, all of this is ugly and there is definitely a better way to do this. However, barring a much more significant re-architecting for what I consider to be a reletively minor improvement, I'm willing to take this small hit to the flow of this code (begrudgingly).
* | | Rename the enum_{prefix,suffix} options to _{prefix,suffix}Robin Dupret2015-07-231-1/+1
| | | | | | | | | | | | | | | | | | This makes it more clear that they are reserved keywords and also it seems less redundant as the line already starts with the call to the `enum` method.
* | | Extra caller details added to ActiveRecord::RecordNotFoundSameer Rahmani2015-07-211-0/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ActiveRecord::RecordNotFound modified to store model name, primary_key and id of the caller model. It allows the catcher of this exception to make a better decision to what to do with it. For example consider this simple example: class SomeAbstractController < ActionController::Base rescue_from ActiveRecord::RecordNotFound, with: :redirect_to_404 private def redirect_to_404(e) return redirect_to(posts_url) if e.model == 'Post' raise end end
* | | Deprecate and rename the keys for association restrict_dependent_destroyRoque Pinel2015-07-201-0/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously `has_one` and `has_many` associations were using the `one` and `many` keys respectively. Both of these keys have special meaning in I18n (they are considered to be pluralizations) so by renaming them to `has_one` and `has_many` we make the messages more explicit and most importantly they don't clash with linguistical systems that need to validate translation keys (and their pluralizations). The `:'restrict_dependent_destroy.one'` key should be replaced with `:'restrict_dependent_destroy.has_one'`, and `:'restrict_dependent_destroy.many'` with `:'restrict_dependent_destroy.has_many'`. [Roque Pinel & Christopher Dell]
* | | Fix state being carried over from previous transactionRoque Pinel2015-07-201-0/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This clears the transaction record state when the transaction finishes with a `:committed` status. Considering the following example where `name` is a required attribute. Before we had `new_record?` returning `true` for a persisted record: ```ruby author = Author.create! name: 'foo' author.name = nil author.save # => false author.new_record? # => true ```
* | | Correctly ignore `mark_for_destruction` without `autosave`Sean Griffin2015-07-201-0/+7
|/ / | | | | | | | | | | | | | | | | As per the docs, `mark_for_destruction` should do nothing if `autosave` is not set to true. We normally persist associations on a record no matter what if the record is a new record, but we were always skipping records which were `marked_for_destruction?`. Fixes #20882
* | Fix counter_cache for polymorphic associationsStefan Kanev2015-07-191-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Also removes a false positive test that depends on the fixed bug: At this time, counter_cache does not work with polymorphic relationships (which is a bug). The test was added to make sure that no StaleObjectError is raised when the car is destroyed. No such error is currently raised because the lock version is not incremented by appending a wheel to the car. Furthermore, `assert_difference` succeeds because `car.wheels.count` does not check the counter cache, but the collection size. The test will fail if it is replaced with `car.wheels_count || 0`.
* | Ensure cyclic associations w/ autosave don't cause duplicate errorsSean Griffin2015-07-181-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This code is so fucked. Things that cause this bug not to replicate: - Defining the validation before the association (we end up calling `uniq!` on the errors in the autosave validation) - Adding `accepts_nested_attributes_for` (I have no clue why. The only thing it does that should affect this is adds `autosave: true` to the inverse reflection, and doing that manually doesn't fix this). This solution is a hack, and I'm almost certain there's a better way to go about it, but this shouldn't cause a huge hit on validation times, and is the simplest way to get it done. Fixes #20874.
* | Ensure that `ActionController::Parameters` can still be passed to ARSean Griffin2015-07-181-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since nested hashes are also instances of `ActionController::Parameters`, and we're explicitly looking to work with a hash for nested attributes, this caused breakage in several points. This is the minimum viable fix for the issue (and one that I'm not terribly fond of). I can't think of a better place to handle this at the moment. I'd prefer to use some sort of solution that doesn't special case AC::Parameters, but we can't use something like `to_h` or `to_a` since `Enumerable` adds both. While I've added a trivial test case for verifying this fix in isolation, we really need better integration coverage to prevent regressions like this in the future. We don't actually have a lot of great places for integration coverage at the moment, so I'm deferring it for now. Fixes #20922.