diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-10-26 13:05:48 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-10-26 13:05:48 +0000 |
commit | a8eea0b04b2989bd054d7c852d636f1cc5494957 (patch) | |
tree | bff2ddce73b205a28bdfe048d74b669b92b20671 /activerecord/lib/active_record/acts | |
parent | 475bd74168a611cf0aeeda42d464aff1b3dfa806 (diff) | |
download | rails-a8eea0b04b2989bd054d7c852d636f1cc5494957.tar.gz rails-a8eea0b04b2989bd054d7c852d636f1cc5494957.tar.bz2 rails-a8eea0b04b2989bd054d7c852d636f1cc5494957.zip |
Fix docs (closes #2491)
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2744 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/acts')
-rw-r--r-- | activerecord/lib/active_record/acts/list.rb | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/acts/nested_set.rb | 26 | ||||
-rw-r--r-- | activerecord/lib/active_record/acts/tree.rb | 13 |
3 files changed, 21 insertions, 20 deletions
diff --git a/activerecord/lib/active_record/acts/list.rb b/activerecord/lib/active_record/acts/list.rb index 425ac3856d..551c41fb6a 100644 --- a/activerecord/lib/active_record/acts/list.rb +++ b/activerecord/lib/active_record/acts/list.rb @@ -6,7 +6,7 @@ module ActiveRecord base.extend(ClassMethods) end - # This act provides the capabilities for sorting and reordering a number of objects in list. + # This act provides the capabilities for sorting and reordering a number of objects in a list. # The class that has this specified needs to have a "position" column defined as an integer on # the mapped database table. # diff --git a/activerecord/lib/active_record/acts/nested_set.rb b/activerecord/lib/active_record/acts/nested_set.rb index cc120cad4b..8b02b358a9 100644 --- a/activerecord/lib/active_record/acts/nested_set.rb +++ b/activerecord/lib/active_record/acts/nested_set.rb @@ -7,17 +7,17 @@ module ActiveRecord end # This acts provides Nested Set functionality. Nested Set is similiar to Tree, but with - # the added feature that you can select the children and all of it's descendants with + # the added feature that you can select the children and all of their descendents with # a single query. A good use case for this is a threaded post system, where you want # to display every reply to a comment without multiple selects. # # A google search for "Nested Set" should point you in the direction to explain the - # data base theory. I figured a bunch of this from + # database theory. I figured out a bunch of this from # http://threebit.net/tutorials/nestedset/tutorial1.html # - # Instead of picturing a leaf node structure with child pointing back to their parent, + # Instead of picturing a leaf node structure with children pointing back to their parent, # the best way to imagine how this works is to think of the parent entity surrounding all - # of it's children, and it's parent surrounding it, etc. Assuming that they are lined up + # of its children, and its parent surrounding it, etc. Assuming that they are lined up # horizontally, we store the left and right boundries in the database. # # Imagine: @@ -42,7 +42,7 @@ module ActiveRecord # | |___________________________| |___________________________| | # |___________________________________________________________________| # - # The numbers represent the left and right boundries. The table them might + # The numbers represent the left and right boundries. The table then might # look like this: # ID | PARENT | LEFT | RIGHT | DATA # 1 | 0 | 1 | 14 | root @@ -63,10 +63,10 @@ module ActiveRecord # There are instance methods for all of these. # # The structure is good if you need to group things together; the downside is that - # keeping data integrity is a pain, and both adding and removing and entry + # keeping data integrity is a pain, and both adding and removing an entry # require a full table write. # - # This sets up a before_destroy trigger to prune the tree correctly if one of it's + # This sets up a before_destroy trigger to prune the tree correctly if one of its # elements gets deleted. # module ClassMethods @@ -134,10 +134,10 @@ module ActiveRecord end - # Added a child to this object in the tree. If this object hasn't been initialized, + # Adds a child to this object in the tree. If this object hasn't been initialized, # it gets set up as a root node. Otherwise, this method will update all of the - # other elements in the tree and shift them to the right. Keeping everything - # balanaced. + # other elements in the tree and shift them to the right, keeping everything + # balanced. def add_child( child ) self.reload child.reload @@ -179,17 +179,17 @@ module ActiveRecord return (self[right_col_name] - self[left_col_name] - 1)/2 end - # Returns a set of itself and all of it's nested children + # Returns a set of itself and all of its nested children def full_set self.class.find(:all, :conditions => "#{scope_condition} AND (#{left_col_name} BETWEEN #{self[left_col_name]} and #{self[right_col_name]})" ) end - # Returns a set of all of it's children and nested children + # Returns a set of all of its children and nested children def all_children self.class.find(:all, :conditions => "#{scope_condition} AND (#{left_col_name} > #{self[left_col_name]}) and (#{right_col_name} < #{self[right_col_name]})" ) end - # Returns a set of only this entries immediate children + # Returns a set of only this entry's immediate children def direct_children self.class.find(:all, :conditions => "#{scope_condition} and #{parent_column} = #{self.id}") end diff --git a/activerecord/lib/active_record/acts/tree.rb b/activerecord/lib/active_record/acts/tree.rb index 9cf5c3f732..1c7646b74c 100644 --- a/activerecord/lib/active_record/acts/tree.rb +++ b/activerecord/lib/active_record/acts/tree.rb @@ -6,8 +6,8 @@ module ActiveRecord base.extend(ClassMethods) end - # Specify this act if you want to model a tree structure by providing a parent association and an children - # association. This act assumes that requires that you have a foreign key column, which by default is called parent_id. + # Specify this act if you want to model a tree structure by providing a parent association and a children + # association. This act requires that you have a foreign key column, which by default is called parent_id. # # class Category < ActiveRecord::Base # acts_as_tree :order => "name" @@ -30,13 +30,14 @@ module ActiveRecord # # In addition to the parent and children associations, the following instance methods are added to the class # after specifying the act: - # * siblings: Return all the children of the parent excluding the current node ([ subchild2 ] when called from subchild1) - # * ancestors: Returns all the ancestors of the current node ([child1, root] when called from subchild2) - # * root: Returns the root of the current node (root when called from subchild2) + # * siblings : Returns all the children of the parent, excluding the current node ([ subchild2 ] when called from subchild1) + # * self_and_siblings : Returns all the children of the parent, including the current node ([ subchild1, subchild2 ] when called from subchild1) + # * ancestors : Returns all the ancestors of the current node ([child1, root] when called from subchild2) + # * root : Returns the root of the current node (root when called from subchild2) module ClassMethods # Configuration options are: # - # * <tt>foreign_key</tt> - specifies the column name to use for track of the tree (default: parent_id) + # * <tt>foreign_key</tt> - specifies the column name to use for tracking 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 = {}) |