aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/attribute_methods
Commit message (Collapse)AuthorAgeFilesLines
* Use mattr_accessor default: option throughout the projectGenadi Samokovarov2017-06-031-2/+1
|
* Add option for class_attribute default (#29270)David Heinemeier Hansson2017-05-292-7/+3
| | | | | | | | | | | | * Allow a default value to be declared for class_attribute * Convert to using class_attribute default rather than explicit setter * Removed instance_accessor option by mistake * False is a valid default value * Documentation
* Move around AR::Dirty and fix _attribute methodAaron Patterson2017-04-141-4/+0
| | | | | | We already have a _read_attribute method that can get the value we need from the model. Lets define that method in AM::Dirty and use the existing one from AR::Dirty rather than introducing a new method.
* Fix inconsistency with changed attributes when overriding AR attribute readerbogdanvlviv2017-04-121-0/+4
|
* Add missing backtick to deprecation messageyuuji.yaginuma2017-03-311-1/+1
|
* Soft-deprecate the top-level HashWithIndifferentAccess classRobin Dupret2017-02-251-3/+3
| | | | | | | Since using a `ActiveSupport::Deprecation::DeprecatedConstantProxy` would prevent people from inheriting this class and extending it from the `ActiveSupport::HashWithIndifferentAccess` one would break the ancestors chain, that's the best option we have here.
* Revert "Merge pull request #27925 from robin850/hwia-removal"Kasper Timm Hansen2017-02-201-3/+3
| | | | | | | | | Pointed out by @matthewd that the HWIA subclass changes the AS scoped class and top-level HWIA hierarchies out from under existing classes. This reverts commit 71da39097b67114329be6d8db7fe6911124531af, reversing changes made to 41c33bd4b2ec3f4a482e6030b6fda15091d81e4a.
* Deprecate the top-level `HashWithIndifferentAccess` contantRobin Dupret2017-02-191-3/+3
| | | | | | | | | This constant was kept for the sake of backward compatibility; it is still available under `ActiveSupport::HashWithIndifferentAccess`. Furthermore, since Ruby 2.5 (https://bugs.ruby-lang.org/issues/11547) won't support top level constant lookup, people would have to update their code anyway.
* Remove unused requireRyuta Kamizono2017-02-121-2/+0
| | | | | | These files are not using `strip_heredoc`. Closes #27976
* Deprecate calling `attr_will_change!` with non-attributesSean Griffin2017-02-111-1/+11
| | | | | | | | | | | | | This was never really intended to work (at least not without calling `define_attribute_methods`, which is less common with Active Record). As we move forward the intention is to require the use of `attribute` over `attr_accessor` for more complex model behavior both on Active Record and Active Model, so this behavior is deprecated. Fixes #27956. Close #27963. [Alex Serban & Sean Griffin]
* Fix inspection behavior when the :id column is not primary keynamusyaka2017-02-091-1/+1
|
* Report the attribute on ActiveRecord::SerializationTypeMismatchKir Shatrov2017-01-291-1/+1
|
* `self.` is not needed when calling its own instance methodAkira Matsuda2017-01-051-1/+1
| | | | Actually, private methods cannot be called with `self.`, so it's not just redundant, it's a bad habit in Ruby
* Merge pull request #27491 from kamipo/add_missing_emit_warningSean Griffin2017-01-031-0/+5
|\ | | | | Add missing `emit_warning_if_needed` for `changed?`
| * Add missing `emit_warning_if_needed` for `changed?`Ryuta Kamizono2016-12-291-0/+5
| |
* | Set time as a timezone aware type and remove related deprecationRafael Mendonça França2016-12-291-23/+2
|/
* Fix Rubocop violations and fix documentation visibilityRafael Mendonça França2016-12-283-3/+3
| | | | | | Some methods were added to public API in 5b14129d8d4ad302b4e11df6bd5c7891b75f393c and they should be not part of the public API.
* Privatize unneededly protected methods in Active RecordAkira Matsuda2016-12-243-6/+6
|
* Check whether the current attribute being write is aliased or not before writingPrathamesh Sonpatki2016-12-091-1/+7
| | | | - If aliased, then use the aliased attribute name.
* Check whether the current attribute being read is aliased or not before readingPrathamesh Sonpatki2016-12-081-1/+6
| | | | | - If aliased, then use the aliased attribute name. - Fixes #26417.
* Correct deprecation warnings in `ActiveRecord::Dirty`Sean Griffin2016-11-301-6/+6
| | | | I had pointed the messages at the new behavior, not the old.
* fix datatime errorSen-Zhang2016-11-011-1/+1
|
* Deprecate the behavior of AR::Dirty inside of after_(create|update|save) ↵Sean Griffin2016-11-012-7/+179
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | callbacks We pretty frequently get bug reports that "dirty is broken inside of after callbacks". Intuitively they are correct. You'd expect `Model.after_save { puts changed? }; model.save` to do the same thing as `model.save; puts model.changed?`, but it does not. However, changing this goes much farther than just making the behavior more intuitive. There are a _ton_ of places inside of AR that can be drastically simplified with this change. Specifically, autosave associations, timestamps, touch, counter cache, and just about anything else in AR that works with callbacks have code to try to avoid "double save" bugs which we will be able to flat out remove with this change. We introduce two new sets of methods, both with names that are meant to be more explicit than dirty. The first set maintains the old behavior, and their names are meant to center that they are about changes that occurred during the save that just happened. They are equivalent to `previous_changes` when called outside of after callbacks, or once the deprecation cycle moves. The second set is the new behavior. Their names imply that they are talking about changes from the database representation. The fact that this is what we really care about became clear when looking at `BelongsTo.touch_record` when tests were failing. I'm unsure that this set of methods should be in the public API. Outside of after callbacks, they are equivalent to the existing methods on dirty. Dirty itself is not deprecated, nor are the methods inside of it. They will only emit the warning when called inside of after callbacks. The scope of this breakage is pretty large, but the migration path is simple. Given how much this can improve our codebase, and considering that it makes our API more intuitive, I think it's worth doing.
* Fixes an issue where time_zone_conversion that causes an exception in ARs ↵Julian Nadeau2016-10-271-1/+1
| | | | | | | | | delegation Following off of https://github.com/rails/rails/issues/15945, I realized that super needs to be the first thing that is called in an AbstractModel's inherited method. I was receiving errors within the inherited method of time_zone_conversion, so I tested locally by moving super to the top of the method declaration. All exceptions went away.
* Revert "Made ActiveRecord consistently use ActiveRecord::Type (not"Sean Griffin2016-10-231-1/+1
| | | | | | This reverts commit 671eb742eec77b5c8281ac2a2e3976ef32a6e424. This is not a change we would like moving forward.
* Made ActiveRecord consistently use ActiveRecord::Type (notIain Beeston2016-10-031-1/+1
| | | | | | | | 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.
* [ci skip] Use right format textAndrey Molchanov2016-09-281-1/+1
|
* Fix broken comments indentation caused by rubocop auto-correct [ci skip]Ryuta Kamizono2016-09-143-20/+20
| | | | | | All indentation was normalized by rubocop auto-correct at 80e66cc4d90bf8c15d1a5f6e3152e90147f00772. But comments was still kept absolute position. This commit aligns comments with method definitions for consistency.
* Fix broken heredoc indentation caused by rubocop auto-correctRyuta Kamizono2016-09-034-23/+23
| | | | | | All indentation was normalized by rubocop auto-correct at 80e66cc4d90bf8c15d1a5f6e3152e90147f00772. But heredocs was still kept absolute position. This commit aligns heredocs indentation for consistency.
* code gardening: removes redundant selfsXavier Noria2016-08-081-1/+1
| | | | | | | | | A few have been left for aesthetic reasons, but have made a pass and removed most of them. Note that if the method `foo` returns an array, `foo << 1` is a regular push, nothing to do with assignments, so no self required.
* revises most Lint/EndAlignment offensesXavier Noria2016-08-071-5/+5
| | | | Some case expressions remain, need to think about those ones.
* applies remaining conventions across the projectXavier Noria2016-08-061-1/+0
|
* normalizes indentation and whitespace across the projectXavier Noria2016-08-067-181/+181
|
* applies new string literal convention in activerecord/libXavier Noria2016-08-065-11/+11
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Merge pull request #25578 from ↵Rafael França2016-07-201-1/+14
|\ | | | | | | | | kamipo/move_warning_about_composite_primary_key_to_attribute_methods_primary_key Move the warning about composite primary key to `AttributeMethods::PrimaryKey`
| * Move the warning about composite primary key to `AttributeMethods::PrimaryKey`Ryuta Kamizono2016-07-021-1/+14
| | | | | | | | | | | | | | | | | | | | | | Actually schema dumper/creation supports composite primary key (#21614). Therefore it should not show the warning about composite primary key in connection adapter. This change moves the warning to `AttributeMethods::PrimaryKey` and suppress the warning for habtm join table. Fixes #25388.
* | Fixes multiparameter attributes conversion with time_zone_aware_attributes ↵alpaca-tc2016-07-191-1/+1
|/ | | | and invalid params
* Support for unified Integer class in Ruby 2.4+Jeremy Daer2016-05-181-1/+1
| | | | | | | | Ruby 2.4 unifies Fixnum and Bignum into Integer: https://bugs.ruby-lang.org/issues/12005 * Forward compat with new unified Integer class in Ruby 2.4+. * Backward compat with separate Fixnum/Bignum in Ruby 2.2 & 2.3. * Drops needless Fixnum distinction in docs, preferring Integer.
* Fix a tip in Active Record time attributes deprecationGenadi Samokovarov2016-03-241-1/+1
| | | | | | | | | | | | | | | I have hit this deprecation in a newly created Rails 5 application and the suggested tip lead me to a `NoMethodError`. It's not trivial to actually make the following work, because of the ActiveRecord::Base class attributes setting dance in the Active Record railtie. config.active_record.time_zone_aware_types << :time Decided to suggest setting it explicitly to the values we need. [ci skip]
* Merge pull request #23395 from PareshGupta/remove-unused-constantSantiago Pastorino2016-02-102-30/+5
|\ | | | | Remove unused ReaderMethodCache and WriterMethodCache constants from ActiveRecord
| * Remove unused class AttributeMethodCachePareshGupta2016-02-021-1/+0
| |
| * remove unused constants from activerecordPareshGupta2016-02-012-30/+6
| |
* | Ensure tz aware attributes continue to work with arraysSean Griffin2016-02-021-1/+1
| | | | | | | | There was a typo in the variable name leading to infinite recursion
* | Avoid infinite recursion when bad values are passed to tz aware fieldsSean Griffin2016-02-021-2/+12
|/ | | | | | | | | | | | | | | We had previously updated this to attempt to map over whatever was passed in, so that additional types like range and array could benefit from this behavior without the time zone converter having to deal with every known type. However, the default behavior of a type is to just yield the given value to `map`, which means that if we don't actually know how to handle a value, we'll just recurse infinitely. Since both uses of `map` in this case occur in cases where we know receiving the same object will recurse, we can just break on reference equality. Fixes #23241.
* Fix the broken buildSean Griffin2016-01-081-0/+2
| | | | | | This is really strange, as it passes on Travis for 2.3, and it passes for me locally on 2.2. But on travis w/ 2.2, passing `Float::INFINITY` in is resulting in an infinite loop. This should resolve it.
* Refactor tz aware types, add support for PG rangesSean Griffin2016-01-081-7/+9
| | | | | | | | | | | | | | | | | This is an alternate implementation to #22875, that generalizes a lot of the logic that type decorators are going to need, in order to have them work with arrays, ranges, etc. The types have the ability to map over a value, with the default implementation being to just yield that given value. Array and Range give more appropriate definitions. This does not automatically make ranges time zone aware, as they need to be added to the `time_zone_aware` types config, but we could certainly make that change if we feel it is appropriate. I do think this would be a breaking change however, and should at least have a deprecation cycle. Closes #22875. /cc @matthewd
* remove extra spaces from deprecation messageyuuji.yaginuma2015-12-151-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ``` # before DEPRECATION WARNING: Time columns will become time zone aware in Rails 5.1. This still causes `String`s to be parsed as if they were in `Time.zone`, and `Time`s to be converted to `Time.zone`. To keep the old behavior, you must add the following to your initializer: config.active_record.time_zone_aware_types = [:datetime] To silence this deprecation warning, add the following: config.active_record.time_zone_aware_types << :time ``` ``` # after DEPRECATION WARNING: Time columns will become time zone aware in Rails 5.1. This still causes `String`s to be parsed as if they were in `Time.zone`, and `Time`s to be converted to `Time.zone`. To keep the old behavior, you must add the following to your initializer: config.active_record.time_zone_aware_types = [:datetime] To silence this deprecation warning, add the following: config.active_record.time_zone_aware_types << :time ```
* applies new doc guidelines to Active Record.Yves Senn2015-10-143-5/+5
| | | | | | | | | | | | | | | | | | | The focus of this change is to make the API more accessible. References to method and classes should be linked to make it easy to navigate around. This patch makes exzessiv use of `rdoc-ref:` to provide more readable docs. This makes it possible to document `ActiveRecord::Base#save` even though the method is within a separate module `ActiveRecord::Persistence`. The goal here is to bring the API closer to the actual code that you would write. This commit only deals with Active Record. The other gems will be updated accordingly but in different commits. The pass through Active Record is not completely finished yet. A follow up commit will change the spots I haven't yet had the time to update. /cc @fxn
* Add Singleton in NullMutationTracker classacapilleri2015-10-031-1/+1
| | | | to reduce allocation of same object
* Build the `AttributeMutationTracker` lazilySean Griffin2015-10-021-13/+15
| | | | | For reads, we never need to construct this object. The double `defined?` check is to avoid errors in tests