Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

merging mrreynolds updates

  • Loading branch information...
commit e3277fb62f38bf32cfc02b84bc7ba0ecf7290fa4 2 parents 47cb28a + e03c40e
Jim Gay saturnflyer authored

Showing 1 changed file with 5 additions and 10 deletions. Show diff stats Hide diff stats

  1. +5 10 lib/active_record/acts/tree.rb
15 lib/active_record/acts/tree.rb
@@ -40,22 +40,17 @@ module ClassMethods
40 40 # * <tt>order</tt> - makes it possible to sort the children according to this SQL snippet.
41 41 # * <tt>counter_cache</tt> - keeps a count in a +children_count+ column if set to +true+ (default: +false+).
42 42 def acts_as_tree(options = {})
43   - configuration = { :foreign_key => "parent_id", :order => nil, :counter_cache => nil, :dependent => :destroy }
  43 + configuration = { :foreign_key => "parent_id", :order => nil, :counter_cache => nil, :dependent => :destroy, :touch => false }
44 44 configuration.update(options) if options.is_a?(Hash)
45 45
46   - belongs_to :parent, :class_name => name, :foreign_key => configuration[:foreign_key], :counter_cache => configuration[:counter_cache]
  46 + belongs_to :parent, :class_name => name, :foreign_key => configuration[:foreign_key], :counter_cache => configuration[:counter_cache], :touch => configuration[:touch]
47 47 has_many :children, :class_name => name, :foreign_key => configuration[:foreign_key], :order => configuration[:order], :dependent => configuration[:dependent]
48 48
49 49 class_eval <<-EOV
50 50 include ActiveRecord::Acts::Tree::InstanceMethods
51   -
52   - def self.roots
53   - find(:all, :conditions => "#{configuration[:foreign_key]} IS NULL", :order => #{configuration[:order].nil? ? "nil" : %Q{"#{configuration[:order]}"}})
54   - end
55   -
56   - def self.root
57   - find(:first, :conditions => "#{configuration[:foreign_key]} IS NULL", :order => #{configuration[:order].nil? ? "nil" : %Q{"#{configuration[:order]}"}})
58   - end
  51 +
  52 + named_scope :roots, :conditions => "#{configuration[:foreign_key]} IS NULL", :order => #{configuration[:order].nil? ? "nil" : %Q{"#{configuration[:order]}"}}
  53 + named_scope :root, :conditions => "#{configuration[:foreign_key]} IS NULL", :order => #{configuration[:order].nil? ? "nil" : %Q{"#{configuration[:order]}"}}, :limit => 1
59 54 EOV
60 55 end
61 56 end

0 comments on commit e3277fb

Please sign in to comment.
Something went wrong with that request. Please try again.