aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/attribute_methods
Commit message (Collapse)AuthorAgeFilesLines
* Fix handling of dirty time zone aware attributesLilibeth De La Cruz2013-02-171-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, when `time_zone_aware_attributes` were enabled, after changing a datetime or timestamp attribute and then changing it back to the original value, `changed_attributes` still tracked the attribute as changed. This caused `[attribute]_changed?` and `changed?` methods to return true incorrectly. Example: in_time_zone 'Paris' do order = Order.new original_time = Time.local(2012, 10, 10) order.shipped_at = original_time order.save order.changed? # => false # changing value order.shipped_at = Time.local(2013, 1, 1) order.changed? # => true # reverting to original value order.shipped_at = original_time order.changed? # => false, used to return true end (cherry picked from commit bc982cbcb34129ea2cfe8aa1f8e0b40e444e68db) Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb Backport of #9073 Fixes #8898
* Revert "Merge pull request #6986 from kennyj/fix_6975"Andrew White2013-01-221-14/+5
| | | | | | | | | This reverts commit 8905c1fb496641c3cdb7b3b816ae6d3d4b2c2b73. Closes #8460 Conflicts: activerecord/test/cases/dirty_test.rb
* Refactor write attribute logic to convert number column valueCarlos Antonio da Silva2013-01-071-4/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is an improvement for issue #8673: "Comparing a BigDecimal to true/false on write_attribute is slow" It seems to be an issue with Ruby itself, related to the "coerce" method being called in TrueClass/FalseClass due to the == condition, triggering method_missing, then raising a NameError that's later catched. This issue was also opened in Ruby tracker: https://bugs.ruby-lang.org/issues/7645. This refactoring avoid the coerce call by using a case statement, which gives us better readability as well. A simple benchmark: ---------- require 'benchmark/ips' require 'bigdecimal' Benchmark.ips do |x| x.report("== true") { BigDecimal('3') == true } x.report("TrueClass") { TrueClass === BigDecimal('3') } x.report("== 0") { BigDecimal('3') == 0 } x.report("Numeric") { Numeric === BigDecimal('3') } end Calculating ------------------------------------- == true 6427 i/100ms TrueClass 47297 i/100ms == 0 35923 i/100ms Numeric 55530 i/100ms ------------------------------------------------- == true 75878.5 (±21.6%) i/s - 359912 in 5.004392s TrueClass 1249547.0 (±13.1%) i/s - 6148610 in 5.035964s == 0 666856.3 (±13.3%) i/s - 3268993 in 5.013789s Numeric 1269300.9 (±11.3%) i/s - 6274890 in 5.028458s ---------- Master has a very different implementation, and there are apparently no similar conversions at this point, it's mainly delegated to the column type cast, but I'll check if something needs to be changed there as well. Closes #8673.
* Serialized attribute can be serialized in an integer columnRafael Mendonça França2012-12-211-0/+8
| | | | | | | | | | Fix #8575 Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/attribute_methods/serialization.rb activerecord/test/cases/serialized_attribute_test.rb activerecord/test/models/person.rb
* Merge pull request #8311 from alisdair/dirty-nullable-datetimeCarlos Antonio da Silva2012-11-251-0/+1
| | | | | | | | | | | Don't call will_change! for datetime nil->"". Setting a nil datetime attribute to a blank string should not cause the attribute to be dirty. Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
* Backport #8078: Fix `attributes_before_type_cast` for serialised attributes.Nikita Afanasenko2012-11-091-0/+10
| | | | Public method attributes_before_type_cast used to return internal AR structure (ActiveRecord::AttributeMethods::Serialization::Attribute), patch fixes this. Now behaves like read_attribute_before_type_cast and returns unserialised values.
* Merge pull request #3544 from amatsuda/_field_changedAaron Patterson2012-09-211-3/+3
| | | | | | | | Rename field_changed? to _field_changed? so that users can create a field named field Conflicts: activerecord/lib/active_record/core.rb activerecord/test/cases/dirty_test.rb
* Merge pull request #6986 from kennyj/fix_6975Rafael Mendonça França2012-08-211-5/+14
| | | | | | | Fix #6975. Round usec when writing timestamp attribute. Conflicts: activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
* Do not consider the numeric attribute as changed if the old value isRafael Mendonça França2012-08-021-1/+1
| | | | | | | | | | | | | | | | | | | | zero and the new value is not a string. Before this commit this was the behavior r = Review.find_by_issue(0) r.issue => 0 r.changes => {} r.issue = 0 => 0 r.changed? => true r.changes => {"issue"=>[0,0]} Fixes #7237
* Merge branch 'acapilleri-update_nested_attributes'Rafael Mendonça França2012-06-211-5/+15
| | | | | | | Closes #6675 Conflicts: activerecord/lib/active_record/attribute_methods/dirty.rb
* Fix #6591. If a field with timezone isn't changed, we don't call will_change!.kennyj2012-06-041-1/+2
|
* Merge pull request #5810 from kennyj/fix_5797Aaron Patterson2012-05-301-3/+4
| | | | | | Fix #5797. Error calling dup method on AR model with serialized field Conflicts: activerecord/lib/active_record/core.rb
* Remove unused 'cast_code' variableKevin Moore2012-04-031-2/+0
|
* Fix #5549.Jon Leighton2012-03-281-3/+6
|
* force datetime attributes to be changedSergey Nartimov2012-03-271-0/+1
| | | | backport ddb5d2f756d9d2655a07791a3b62832efd588474 to 3-2-stable
* Fix attribute_before_type_cast for serialized attributes. Fixes #4837.Jon Leighton2012-02-071-0/+8
| | | | | | Conflicts: activerecord/lib/active_record/core.rb
* Allow writing unknown attributes, but with a deprecation warning. Closes #4583.Jon Leighton2012-01-311-4/+7
|
* Doh, remove debugging lineJon Leighton2011-12-231-1/+0
|
* Fix #4046.Jon Leighton2011-12-231-4/+3
|
* Make read_attribute code path accessible at the class levelJon Leighton2011-12-222-27/+33
|
* Fix the build on postgres. Note: we should probably actually make schema ↵Jon Leighton2011-12-161-1/+1
| | | | mutations bust the cache.
* Don't store defaults in the schema cacheJon Leighton2011-12-161-2/+2
|
* Cache columns at the model level.Jon Leighton2011-12-161-2/+0
| | | | Allows two models to use the same table but have different primary keys.
* Split out most of the AR::Base code into separate modules :cake:Jon Leighton2011-12-151-0/+12
|
* Fix #3987.Jon Leighton2011-12-151-0/+2
|
* Stop the build asploding on 1.8.7Jon Leighton2011-12-141-0/+2
|
* Use a separate module for 'external' attribute methods.Jon Leighton2011-12-142-17/+12
|
* use the schema cache when asking for the primary keyAaron Patterson2011-12-121-1/+1
|
* fixing eval'd line numbers.Aaron Patterson2011-12-081-2/+2
|
* Fix #3837.Jon Leighton2011-12-031-11/+5
| | | | | We also need to time zone convert time zone aware attributes when accessed via read_attribute, not only when via direct access.
* Revert "Roflscaling!" (for now)Jon Leighton2011-12-022-8/+11
| | | | | | | | This reverts commit f6b5046305d43c5f64bcb6fed0e44f7bca99a603. Fear not, the roflscale will return when I have a bit more time and figure out a better way to do it. (In particular, a way that doesn't break the build.)
* Fewer string allocations in attribute methodJon Leighton2011-12-011-4/+4
|
* Roflscaling!Jon Leighton2011-12-012-11/+8
| | | | | Don't prefix the name with attribute_. Avoids a string allocation on read_attribute, which is a bit faster.
* Create method with known identifier then alias into place.Jon Leighton2011-12-011-25/+21
| | | | | | | | This means we never have to rely on define_method (which is slower and uses more memory), even when we have attributes containing characters that are not allowed in standard method names. (I am mainly changing this because the duplication annoys me, though.)
* Remove some unnecessary code etcJon Leighton2011-12-012-26/+11
|
* Add test for read_attribute(:id) with non-standard PK.Jon Leighton2011-12-012-4/+18
| | | | | | | | Also make it actually work. It slows down all read_attribute accesses to map 'id' to whatever the PK actually is, inside read_attribute. So instead make sure the necessary methods are defined and that they redirect wherever they need to go.
* Remove the need for type_cast_attribute.Jon Leighton2011-12-013-42/+47
| | | | This is good because it reduces duplication.
* Get rid of the underscore versions of attribute methods!Jon Leighton2011-12-013-6/+33
| | | | This makes me happy!
* Don't rely on underscore-prefixed attribute methods.Jon Leighton2011-12-013-48/+80
| | | | | | Define singleton methods on the attributes module instead. This reduces method pollution on the actual model classes. It also seems to make something faster, I am unsure why! O_o
* If the table behind has no primary key, do not ask again and just return nil.Julius de Bruijn2011-11-301-1/+2
|
* consistencyJon Leighton2011-11-303-16/+16
|
* Don't check column type, you might implement a custom coder that serializes ↵Jon Leighton2011-11-301-1/+1
| | | | to a different type
* omg computer science!Jon Leighton2011-11-302-22/+44
| | | | | | | Implement a mini state machine for serialized attributes. This means we do not have to deserialize the values upon initialization, which means that if we never actually access the attribute, we never have to deserialize it.
* Don't need second paramJon Leighton2011-11-302-4/+4
|
* No longer need to undef id as we are defining it ourselvesJon Leighton2011-11-301-3/+0
|
* Move some serialization stuff out of BaseJon Leighton2011-11-301-0/+42
|
* Extract attribute serialization code into a separate moduleJon Leighton2011-11-302-28/+47
|
* Use inheritance to avoid special-case code for the 'id' methodJon Leighton2011-11-303-8/+20
|
* #id is an alias for whatever the primary key isJon Leighton2011-11-301-1/+1
|
* fix indentJon Leighton2011-11-301-3/+3
|