diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2004-12-31 16:53:41 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2004-12-31 16:53:41 +0000 |
commit | f0a3397c47c557b80be516f4236a13afc7b7f65e (patch) | |
tree | be1c009f15cce95fdd8fe3cfdbc7070975da729e /activerecord | |
parent | 2dd2b56482a4e102251258e3c2458618de8897c2 (diff) | |
download | rails-f0a3397c47c557b80be516f4236a13afc7b7f65e.tar.gz rails-f0a3397c47c557b80be516f4236a13afc7b7f65e.tar.bz2 rails-f0a3397c47c557b80be516f4236a13afc7b7f65e.zip |
Added :counter_cache option to acts_as_tree that works just like the one you can define on belongs_to #371 [Josh]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@291 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/acts/tree.rb | 5 |
2 files changed, 5 insertions, 2 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index 455748b98c..b97085cdba 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Added :counter_cache option to acts_as_tree that works just like the one you can define on belongs_to #371 [Josh] + * Fixed quoting in validates_format_of that would allow some rules to pass regardless of input #390 [Dmitry V. Sabanin] * Fixed broken transactions that were actually only running object-level and not db level transactions [andreas] diff --git a/activerecord/lib/active_record/acts/tree.rb b/activerecord/lib/active_record/acts/tree.rb index c01b6f7ab7..61163941d3 100644 --- a/activerecord/lib/active_record/acts/tree.rb +++ b/activerecord/lib/active_record/acts/tree.rb @@ -31,11 +31,12 @@ module ActiveRecord # # * <tt>foreign_key</tt> - specifies the column name to use for track of the tree (default: parent_id) # * <tt>order</tt> - makes it possible to sort the children according to this SQL snippet. + # * <tt>counter_cache</tt> - keeps a count in a children_count column if set to true (default: false). def acts_as_tree(options = {}) - configuration = { :foreign_key => "parent_id", :order => nil } + configuration = { :foreign_key => "parent_id", :order => nil, :counter_cache => nil } configuration.update(options) if options.is_a?(Hash) - belongs_to :parent, :class_name => name, :foreign_key => configuration[:foreign_key] + belongs_to :parent, :class_name => name, :foreign_key => configuration[:foreign_key], :counter_cache => configuration[:counter_cache] has_many :children, :class_name => name, :foreign_key => configuration[:foreign_key], :order => configuration[:order], :dependent => true end end |