aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/attribute_methods
Commit message (Collapse)AuthorAgeFilesLines
* assigning '0.0' to a nullable numeric column does not make it dirtyYves Senn2013-03-051-1/+5
|
* Reduced memory leak problem in transactions by lazily updating AR objects ↵wangjohn2013-02-201-0/+5
| | | | with new transaction state. If AR object has a callback, the callback will be performed immediately (non-lazily) so the transaction still has to keep records with callbacks.
* Gist URLs are now namespacedAkira Matsuda2013-02-181-1/+1
| | | | see: https://github.com/blog/1406-namespaced-gists
* Simplify type casting code for timezone aware attributesAndrew White2013-01-261-10/+5
| | | | | | With the addition of String#in_time_zone and Date#in_time_zone we can simplify the type casting code by checking if the value has an `in_time_zone` method.
* Fix handling of dirty time zone aware attributesLilibeth De La Cruz2013-01-261-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
* Revert "Round usec when writing timestamp attribute."Andrew White2013-01-221-13/+5
| | | | | | | | | | This reverts commit e9d2ad395ec2ef929d74752f3d71c80674044fbe. Closes #8460 Conflicts: activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb activerecord/test/cases/dirty_test.rb
* change unless !blank? to if blank? in get_primary_keyAngelo capilleri2013-01-081-1/+1
|
* These are already required through AS/railsAkira Matsuda2013-01-071-1/+0
| | | | | | * dependencies/autoload * concern * deprecation
* Rename update_attributes method to update, keep update_attributes as an aliasAmparo Luna + Guillermo Iguaran2013-01-031-2/+2
|
* Serialized attribute can be serialized in an integer columnRafael Mendonça França2012-12-211-0/+8
| | | | Fix #8575
* Don't call will_change! for datetime nil->"".Alisdair McDiarmid2012-11-251-0/+1
| | | | | | | Setting a nil datetime attribute to a blank string should not cause the attribute to be dirty. Fix #8310
* Don't allocate new strings in compiled attribute methodsJon Leighton2012-11-212-20/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This improves memory and performance without having to use symbols which present DoS problems. Thanks @headius and @tenderlove for the suggestion. This was originally committed in f1765019ce9b6292f2264b4601dad5daaffe3a89, and then reverted in d3494903719682abc0948bef290af0d3d7b5a440 due to it causing problems in a real application. This second attempt should solve that. Benchmark --------- require 'active_record' require 'benchmark/ips' ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:') class Post < ActiveRecord::Base connection.create_table :posts, force: true do |t| t.string :name end end post = Post.create name: 'omg' Benchmark.ips do |r| r.report('Post.new') { Post.new name: 'omg' } r.report('post.name') { post.name } r.report('post.name=') { post.name = 'omg' } r.report('Post.find(1).name') { Post.find(1).name } end Before ------ Calculating ------------------------------------- Post.new 1419 i/100ms post.name 7538 i/100ms post.name= 3024 i/100ms Post.find(1).name 243 i/100ms ------------------------------------------------- Post.new 20637.6 (±12.7%) i/s - 102168 in 5.039578s post.name 1167897.7 (±18.2%) i/s - 5186144 in 4.983077s post.name= 64305.6 (±9.6%) i/s - 317520 in 4.998720s Post.find(1).name 2678.8 (±10.8%) i/s - 13365 in 5.051265s After ----- Calculating ------------------------------------- Post.new 1431 i/100ms post.name 7790 i/100ms post.name= 3181 i/100ms Post.find(1).name 245 i/100ms ------------------------------------------------- Post.new 21308.8 (±12.2%) i/s - 105894 in 5.053879s post.name 1534103.8 (±2.1%) i/s - 7634200 in 4.979405s post.name= 67441.0 (±7.5%) i/s - 337186 in 5.037871s Post.find(1).name 2681.9 (±10.6%) i/s - 13475 in 5.084511s
* Remove return guardCarlos Antonio da Silva2012-11-171-2/+1
|
* Keep the code related to serialization in Serialization module.Nikita Afanasenko2012-11-101-1/+9
| | | | We should not need any `serialized_attributes` checks outside `ActiveRecord::AttributeMethods::Serialization` module.
* Merge branch 'master' of github.com:lifo/docrailsVijay Dev2012-11-031-0/+43
|\ | | | | | | | | | | | | Conflicts: actionpack/lib/action_controller/metal/mime_responds.rb activerecord/lib/active_record/attribute_methods.rb guides/source/working_with_javascript_in_rails.md
| * Fix code example in AR::AttributeMethods::BeforeTypeCast.Hendy Tanata2012-10-221-1/+1
| |
| * add docs to AR::AttributeMethods::BeforeTypeCast [ci skip]Francesco Rodriguez2012-10-211-0/+23
| |
| * fix typo and improve example [ci skip]Francesco Rodriguez2012-10-211-1/+3
| |
| * update AR::AttributeMethods::BeforeTypeCast docs [ci skip]Francesco Rodriguez2012-10-211-0/+18
| |
* | Revert "Don't allocate new strings in compiled attribute methods"David Heinemeier Hansson2012-10-312-39/+20
| | | | | | | | This reverts commit f1765019ce9b6292f2264b4601dad5daaffe3a89.
* | Fix `attributes_before_type_cast` for serialised attributes.Nikita Afanasenko2012-10-311-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.
* | Make caller attribute in deprecation methods optionalAlexey Gaziev2012-10-301-1/+1
| |
* | Provide a call stack for deprecation warnings where needed.Nikita Afanasenko2012-10-291-1/+2
| | | | | | | | It's sometimes hard to quickly find where deprecated call was performed, especially in case of migrating between Rails versions. So this is an attempt to improve the call stack part of the warning message by providing caller explicitly.
* | Remove ActiveRecord::ModelJon Leighton2012-10-263-24/+9
|/ | | | | | | | | | In the end I think the pain of implementing this seamlessly was not worth the gain provided. The intention was that it would allow plain ruby objects that might not live in your main application to be subclassed and have persistence mixed in. But I've decided that the benefit of doing that is not worth the amount of complexity that the implementation introduced.
* Revert "Get rid of the ActiveRecord::Model::DeprecationProxy thing."Jeremy Kemper2012-10-203-3/+3
| | | | This reverts commit 83846838252397b3781eed165ca301e05db39293.
* Get rid of the ActiveRecord::Model::DeprecationProxy thing.Jon Leighton2012-10-193-3/+3
| | | | | | | | | | | | | | | | | I think it's going to be too much pain to try to transition the :active_record load hook from executing against Base to executing against Model. For example, after Model is included in Base, and modules included in Model will no longer get added to the ancestors of Base. So plugins which wish to be compatible with both Model and Base should use the :active_record_model load hook which executes *before* Base gets loaded. In general, ActiveRecord::Model is an advanced feature at the moment and probably most people will continue to inherit from ActiveRecord::Base for the time being.
* Rename the partial_updates config to partial_writesJon Leighton2012-10-191-6/+18
| | | | This reflects the fact that it now impact inserts as well as updates.
* The default value of a text/blob in mysql strict mode should be nilJon Leighton2012-10-191-11/+1
| | | | | | | | | In non-strict mode it is '', but if someone is in strict mode then we should honour the strict semantics. Also, this removes the need for a completely horrible hack in dirty.rb. Closes #7780
* Don't allocate new strings in compiled attribute methodsJon Leighton2012-10-122-20/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This improves memory and performance without having to use symbols which present DoS problems. Thanks @headius and @tenderlove for the suggestion. Benchmark --------- require 'active_record' require 'benchmark/ips' ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:') class Post < ActiveRecord::Base connection.create_table :posts, force: true do |t| t.string :name end end post = Post.create name: 'omg' Benchmark.ips do |r| r.report('Post.new') { Post.new name: 'omg' } r.report('post.name') { post.name } r.report('post.name=') { post.name = 'omg' } r.report('Post.find(1).name') { Post.find(1).name } end Before ------ Calculating ------------------------------------- Post.new 1419 i/100ms post.name 7538 i/100ms post.name= 3024 i/100ms Post.find(1).name 243 i/100ms ------------------------------------------------- Post.new 20637.6 (±12.7%) i/s - 102168 in 5.039578s post.name 1167897.7 (±18.2%) i/s - 5186144 in 4.983077s post.name= 64305.6 (±9.6%) i/s - 317520 in 4.998720s Post.find(1).name 2678.8 (±10.8%) i/s - 13365 in 5.051265s After ----- Calculating ------------------------------------- Post.new 1431 i/100ms post.name 7790 i/100ms post.name= 3181 i/100ms Post.find(1).name 245 i/100ms ------------------------------------------------- Post.new 21308.8 (±12.2%) i/s - 105894 in 5.053879s post.name 1534103.8 (±2.1%) i/s - 7634200 in 4.979405s post.name= 67441.0 (±7.5%) i/s - 337186 in 5.037871s Post.find(1).name 2681.9 (±10.6%) i/s - 13475 in 5.084511s
* Revert "Key the attributes hash with symbols"Jon Leighton2012-10-123-12/+8
| | | | | | | | | | | | This reverts commit 86c3dfbd47cb96af02daaa655963292b1a1b110e. Conflicts: activerecord/lib/active_record/attribute_methods/read.rb Reason: whilst this increased performance, it also presents a DoS risk via memory exhaustion if users were allowing user input to dictate the arguments of read/write_attribute. I will investigate alternative ways to cut down on string allocations here.
* Merge branch 'master' of github.com:lifo/docrailsVijay Dev2012-09-285-30/+40
|\ | | | | | | | | Conflicts: actionpack/lib/action_view/helpers/asset_tag_helper.rb
| * update AR/attribute_methods documentation [ci skip]Francesco Rodriguez2012-09-214-26/+36
| |
| * fix AR::AttributeMethods::Dirty :nodoc: [ci skip]Francesco Rodriguez2012-09-211-4/+4
| |
* | Support for partial inserts.Jon Leighton2012-09-281-3/+17
| | | | | | | | | | | | | | | | | | | | | | When inserting new records, only the fields which have been changed from the defaults will actually be included in the INSERT statement. The other fields will be populated by the database. This is more efficient, and also means that it will be safe to remove database columns without getting subsequent errors in running app processes (so long as the code in those processes doesn't contain any references to the removed column).
* | Removing dead code. attribute_cast_code is not called.kennyj2012-09-282-25/+0
|/
* Set primary key with id= only if primary key existsGuillermo Iguaran2012-09-161-1/+1
|
* Remove mass assignment security from ActiveRecordGuillermo Iguaran2012-09-161-2/+1
|
* Raise MissingAttributeError on query methodsErnie Miller2012-09-081-1/+1
| | | | | | | | | | | | | When calling a query method on an attribute that was not selected by an ActiveRecord query, an ActiveModel::MissingAttributeError is not raised. Instead, a nil value is returned, which will return false once cast to boolean. This is undesirable, as we should not give the impression that we know the attribute's boolean value when we haven't loaded the attribute's (possibly) non-boolean value from the database. This issue is present on versions going back as far as 2.3, at least.
* Minor refactor in ActiveRecord#initialize_dupCarlos Antonio da Silva2012-09-071-1/+0
| | | | | | * There is no need to delete the primary key from cloned attributes, since it sets the same pk to nil afterwards. * Check for empty? instead of any? to run initialize callbacks.
* Avoid #fetch for non-nil values.Jon Leighton2012-08-311-1/+2
| | | | | | This is purely a performance optimisation. See https://gist.github.com/3552829
* Key the attributes hash with symbolsJon Leighton2012-08-313-7/+12
| | | | | | | | This is a performance/GC optimisation. In theory, this could be optimised by the implementation (last time I checked, this would have no effect on JRuby). But in practise, this make attribute access faster.
* call methods on AR::Model after ClassMethods module is definedAaron Patterson2012-08-241-1/+2
|
* Use instance_accessor: false instead of instance_writer.kennyj2012-08-211-2/+7
|
* Round usec when writing timestamp attribute.kennyj2012-08-211-5/+14
|
* Pull more serialize code into a lazy included moduleJon Leighton2012-08-171-60/+63
|
* Optimize instantiation for models which don't use serializeJon Leighton2012-08-171-13/+20
| | | | Those z's were hard to type.
* load active_support/core_ext/class/attribute in active_support/railsXavier Noria2012-08-022-2/+0
|
* load active_support/core_ext/object/inclusion in active_support/railsXavier Noria2012-08-021-1/+0
|
* load active_support/core_ext/object/blank in active_support/railsXavier Noria2012-08-022-2/+0
|
* 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 Conflicts: activerecord/CHANGELOG.md