| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
|
|
|
|
|
|
|
|
| |
This reverts commit 8905c1fb496641c3cdb7b3b816ae6d3d4b2c2b73.
Closes #8460
Conflicts:
activerecord/test/cases/dirty_test.rb
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
|
|
| |
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
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
| |
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
|
|
|
|
|
|
|
| |
Fix #6975. Round usec when writing timestamp attribute.
Conflicts:
activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
|
|
|
|
|
|
| |
Closes #6675
Conflicts:
activerecord/lib/active_record/attribute_methods/dirty.rb
|
| |
|
|
|
|
|
|
| |
Fix #5797. Error calling dup method on AR model with serialized field
Conflicts:
activerecord/lib/active_record/core.rb
|
| |
|
| |
|
|
|
|
| |
backport ddb5d2f756d9d2655a07791a3b62832efd588474 to 3-2-stable
|
|
|
|
|
|
| |
Conflicts:
activerecord/lib/active_record/core.rb
|
| |
|
| |
|
| |
|
| |
|
|
|
|
| |
mutations bust the cache.
|
| |
|
|
|
|
| |
Allows two models to use the same table but have different primary keys.
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
|
|
|
|
| |
We also need to time zone convert time zone aware attributes when
accessed via read_attribute, not only when via direct access.
|
|
|
|
|
|
|
|
| |
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.)
|
| |
|
|
|
|
|
| |
Don't prefix the name with attribute_. Avoids a string allocation on
read_attribute, which is a bit faster.
|
|
|
|
|
|
|
|
| |
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.)
|
| |
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
| |
This is good because it reduces duplication.
|
|
|
|
| |
This makes me happy!
|
|
|
|
|
|
| |
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
|
| |
|
| |
|
|
|
|
| |
to a different type
|
|
|
|
|
|
|
| |
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.
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|