aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/core.rb
Commit message (Collapse)AuthorAgeFilesLines
* remove unused config optionJon Leighton2012-10-261-3/+0
|
* Remove ActiveRecord::ModelJon Leighton2012-10-261-73/+71
| | | | | | | | | | 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-201-1/+1
| | | | This reverts commit 83846838252397b3781eed165ca301e05db39293.
* Get rid of the ActiveRecord::Model::DeprecationProxy thing.Jon Leighton2012-10-191-1/+1
| | | | | | | | | | | | | | | | | 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.
* Update docs for AR::Base#new to remove references to mass_assignment_optionsGuillermo Iguaran2012-09-181-10/+1
|
* Remove mass_assignment_options from ActiveRecordGuillermo Iguaran2012-09-161-3/+3
|
* Revert "create a transaction object and point AR objects at that object ↵Jon Leighton2012-09-151-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | during a" This reverts commit c24c885209ac2334dc6f798c394a821ee270bec6. Here's the explanation I just sent to @tenderlove: Hey, I've been thinking about about the transaction memory leak thing that we were discussing. Example code: post = nil Post.transaction do N.times { post = Post.create } end Post.transaction is going to create a real transaction and there will also be a (savepoint) transaction inside each Post.create. In an idea world, we'd like all but the last Post instance to be GC'd, and for the last Post instance to receive its after_commit callback when Post.transaction returns. I can't see how this can work using your solution where the Post itself holds a reference to the transaction it is in; when Post.transaction returns, control does not switch to any of Post's instance methods, so it can't trigger the callbacks itself. What we really want is for the transaction itself to hold weak references to the objects within the transaction. So those objects can be GC'd, but if they are not GC'd then the transaction can iterate them and execute their callbacks. I've looked into WeakRef implementations that are available. On 1.9.3, the stdlib weakref library is broken and we shouldn't use it. There is a better implementation here: https://github.com/bdurand/ref/blob/master/lib/ref/weak_reference/pure_ruby.rb We could use that, either by pulling in the gem or just copying the code in, but it still suffers from the limitation that it uses ObjectSpace finalizers. In my testing, this finalizers make GC quite expensive: https://gist.github.com/3722432 Ruby 2.0 will have a native WeakRef implementation (via ObjectSpace::WeakMap), hence won't be reliant on finalizers: http://bugs.ruby-lang.org/issues/4168 So the ultimate solution will be for everyone to use Ruby 2.0, and for us to just use ObjectSpace::WeakMap. In the meantime, we have basically 3 options: The first is to leave it as it is. The second is to use a finalizer-based weakref implementation and take the GC perf hit. The final option is to store object ids rather than the actual objects. Then use ObjectSpace._id2ref to deference the objects at the end of the transaction, if they exist. This won't stop memory use growing within the transaction, but it'll grow more slowly. I benchmarked the performance of _id2ref this if the object does or does not exist: https://gist.github.com/3722550 If it does exist it seems decent, but it's hugely more expensive if it doesn't, probably because we have to do the rescue nil. Probably most of the time the objects will exist. However the point of doing this optimisation is to allow people to create a large number of objects inside a transaction and have them be GC'd. So for that use case, we'd be replacing one problem with another. I'm not sure which of the two problems is worse. My feeling is that we should just leave this for now and come back to it when Ruby 2.0 is out. I'm going to revert your commit because I can't see how it solves this. Hope you don't mind... if I've misunderstood then let me know! Jon
* Minor refactor in ActiveRecord#initialize_dupCarlos Antonio da Silva2012-09-071-10/+4
| | | | | | * 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.
* create a transaction object and point AR objects at that object during aAaron Patterson2012-09-071-0/+1
| | | | transaction.
* initialize instance variables for transactions to remove conditionalsAaron Patterson2012-08-201-0/+1
|
* Avoid #any?Jon Leighton2012-08-171-1/+1
| | | | | | any? will check that each item in the array is truthy, as opposed to !empty? which will simply check that the array has length. For an empty array, !empty? still seems to be faster than any?
* Avoid deep_dup when intantiating.Jon Leighton2012-08-171-2/+5
| | | | | deep_dup is slow. we only need to dup the values, so just do that directly.
* Remove the dependent_restrict_raises option.Jon Leighton2012-08-101-9/+0
| | | | | | | | | | | | | | | It's not really a good idea to have this as a global config option. We should allow people to specify the behaviour per association. There will now be two new values: * :dependent => :restrict_with_exception implements the current behaviour of :restrict. :restrict itself is deprecated in favour of :restrict_with_exception. * :dependent => :restrict_with_error implements the new behaviour - it adds an error to the owner if there are dependent records present See #4727 for the original discussion of this.
* load active_support/core_ext/module/delegation in active_support/railsXavier Noria2012-08-021-1/+0
|
* load active_support/concern in active_support/railsXavier Noria2012-08-021-1/+0
|
* Revert "Removing composed_of from ActiveRecord."Rafael Mendonça França2012-07-271-0/+2
| | | | | | | | | | | This reverts commit 14fc8b34521f8354a17e50cd11fa3f809e423592. Reason: we need to discuss a better path from this removal. Conflicts: activerecord/lib/active_record/reflection.rb activerecord/test/cases/base_test.rb activerecord/test/models/developer.rb
* Fix activerecord model to_ary method comment 'see also' linkKang Wen2012-07-161-1/+1
|
* Removing composed_of from ActiveRecord.Steve Klabnik2012-06-181-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This feature adds a lot of complication to ActiveRecord for dubious value. Let's talk about what it does currently: class Customer < ActiveRecord::Base composed_of :balance, :class_name => "Money", :mapping => %w(balance amount) end Instead, you can do something like this: def balance @balance ||= Money.new(value, currency) end def balance=(balance) self[:value] = balance.value self[:currency] = balance.currency @balance = balance end Since that's fairly easy code to write, and doesn't need anything extra from the framework, if you use composed_of today, you'll have to add accessors/mutators like that. Closes #1436 Closes #2084 Closes #3807
* Simplify AR configuration code.Jon Leighton2012-06-151-63/+74
| | | | | Get rid of ActiveModel::Configuration, make better use of ActiveSupport::Concern + class_attribute, etc.
* Ensure that mass assignment options are preservedAndrew White2012-06-101-9/+10
| | | | | | | | | | | | | | | | There are two possible scenarios where the @mass_assignment_options instance variable can become corrupted: 1. If the assign_attributes doesn't complete correctly, then subsequent calls to a nested attribute assignment method will use whatever options were passed to the previous assign_attributes call. 2. With nested assign_attributes calls, the inner call will overwrite the current options. This will only affect nested attributes as the attribute hash is sanitized before any methods are called. To fix this we save the current options in a local variable and then restore these options in an ensure block.
* Fix #5797. Error calling dup method on AR model with serialized fieldkennyj2012-05-301-1/+1
|
* remove unnecessary ruby 1.8 reference from active_record/core [ci skip]Francesco Rodriguez2012-05-261-3/+4
|
* Fix typo.Peter Suschlik2012-05-181-1/+1
|
* Merge branch 'master' of github.com:lifo/docrailsVijay Dev2012-05-171-1/+1
|\ | | | | | | | | Conflicts: activerecord/lib/active_record/core.rb
| * Fix typos in docs for ActiveRecord::Core::arel_table [ci skip]Mark Rushakoff2012-05-161-3/+1
| |
| * Fix typo [ci skip]Peter Suschlik2012-05-151-1/+1
| |
* | Remove extra `end` in arel_table docs. [ci skip]Carlos Antonio da Silva2012-05-151-8/+6
|/ | | | Introduced in 7ecfe3d30ccfaee8dcca4ee649cc006c090bdfb4
* Merge branch 'master' of github.com:lifo/docrailsVijay Dev2012-05-151-0/+8
|\ | | | | | | | | Conflicts: actionpack/lib/action_view/helpers/asset_tag_helper.rb
| * Add documentation for arel_tableOscar Del Ben2012-05-141-0/+8
| |
* | fixes a nodoc which swallowed the documentation for the rest of the methods ↵Vijay Dev2012-05-121-2/+1
|/ | | | [ci skip]
* Merge branch 'master' of github.com:lifo/docrailsVijay Dev2012-05-121-1/+23
|\ | | | | | | | | Conflicts: activesupport/lib/active_support/callbacks.rb
| * copy edits [ci skip]Vijay Dev2012-05-121-4/+1
| |
| * Better document the difference between #clone and #dup.Erich Menge2012-05-111-1/+26
| | | | | | | | | | Add #nodoc to initialize_dup and use :method: to document the #dup method. Relates to issue #6235
* | s/wether/whether [ci skip]Vijay Dev2012-05-121-1/+1
|/
* Use deep_dup in aciverecord default columns assignmentPiotr Sarnacki2012-05-061-4/+2
|
* Duplicate column_defaults properly (closes #6115)Piotr Sarnacki2012-05-041-1/+4
|
* Removes caching from ActiveRecord::Core::ClassMethods#relationBenedikt Deicke2012-04-031-4/+3
| | | | | | | | | | | The #relation method gets called in four places and the return value was instantly cloned in three of them. The only place that did not clone was ActiveRecord::Scoping::Default::ClassMethods#unscoped. This introduced a bug described in #5667 and should really clone the relation, too. This means all four places would clone the relation, so it doesn't make a lot of sense caching it in the first place. The four places with calls to relations are: activerecord/lib/active_record/scoping/default.rb:110:in `block in build_default_scope'" activerecord/lib/active_record/scoping/default.rb:42:in `unscoped'" activerecord/lib/active_record/scoping/named.rb:38:in `scoped'" activerecord/lib/active_record/scoping/named.rb:52:in `scope_attributes'"
* Add ActiveRecord::Base#slice to slice method callsGuillermo Iguaran2012-03-291-0/+6
|
* ActiveRecord::Core#initialize: improve performanceBogdan Gusiev2012-03-151-1/+1
|
* Fix GH #5399. connection_pools's keys are ↵kennyj2012-03-141-1/+1
| | | | ActiveRecord::Base::ConnectionSpecification objects.
* Initialize @stale_state to nil in associationCarlos Antonio da Silva2012-03-041-1/+0
| | | | | | | | | | | | | This apparently fix the warning related to @new_record variable not being initialized in AR's test suit, when an association is built and the object is marshalled/loaded. See these tests in AR's base_test.rb: test_marshalling_with_associations test_marshalling_new_record_round_trip_with_associations Closes #3720.
* Rename field_changed? to _field_changed? so that users can create a field ↵Akira Matsuda2012-02-141-1/+1
| | | | named field
* Merge branch 'master' into instance_readerAaron Patterson2012-02-091-1/+3
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: (30 commits) Bump tzinfo. 0.3.31 was released on November 6, 2011. Fix GH #4909. Dependency on TZInfo move from AR to AS. moving ordered hash to normal hash because ruby 1.9.3 hash defaultly ordered one Refactored the OrderedHash related stuff Replaced OrderedHash usage with Ruby 1.9 Hash Replaced OrderedHash with Hash for ruby 1.9 series removed unnecessary code replacing the orderhash with hash for ruby-1.9 Clean up some wording. Fix typo. test title changed corresponding to the test replaced active support ordered hash to ruby hash on active resource PostgreSQL does not work in the same way of the other adapters AR::Relation#pluck: improve to work with joins Fix match docs Fix attribute_before_type_cast for serialized attributes. Fixes #4837. Fix failing request test Fixes in AMo README Update README to mention lint. Trim down Active Model API by removing valid? and errors.full_messages ...
| * Merge branch 'master' of github.com:lifo/docrailsVijay Dev2012-02-091-1/+1
| |\ | | | | | | | | | | | | Conflicts: activerecord/lib/active_record/relation/query_methods.rb
| | * Correcting ActiveRecord::Core#encode_with docsJosef Šimánek2012-02-071-1/+1
| | |
| * | Fix attribute_before_type_cast for serialized attributes. Fixes #4837.Jon Leighton2012-02-071-0/+2
| |/
* | wrap and cache columns for typecastingAaron Patterson2012-02-071-2/+2
| |
* | column types are passed from the result set to the instantiated AR objectAaron Patterson2012-02-071-2/+3
| |
* | copy the columns hash to the active record instances, typecast using columns ↵Aaron Patterson2012-02-071-0/+2
|/ | | | looked up on the instance
* has_many/has_one, :dependent => :restrict, deprecation added.Manoj2012-01-291-0/+10
|