Skip to content
This repository
Browse code

Doc fix (closes #5504) [lee@omara.ca]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4543 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit b272100f05aa3669efe1ad4d0d7b4299a568f1c0 1 parent f780bb8
David Heinemeier Hansson dhh authored
16 activerecord/lib/active_record/acts/list.rb
@@ -77,7 +77,8 @@ module InstanceMethods
77 77 def insert_at(position = 1)
78 78 insert_at_position(position)
79 79 end
80   -
  80 +
  81 + # Swap positions with the next lower item, if one exists.
81 82 def move_lower
82 83 return unless lower_item
83 84
@@ -87,6 +88,7 @@ def move_lower
87 88 end
88 89 end
89 90
  91 + # Swap positions with the next higher item, if one exists.
90 92 def move_higher
91 93 return unless higher_item
92 94
@@ -96,6 +98,8 @@ def move_higher
96 98 end
97 99 end
98 100
  101 + # Move to the bottom of the list. If the item is already in the list, the items below it have their
  102 + # position adjusted accordingly.
99 103 def move_to_bottom
100 104 return unless in_list?
101 105 acts_as_list_class.transaction do
@@ -104,6 +108,8 @@ def move_to_bottom
104 108 end
105 109 end
106 110
  111 + # Move to the top of the list. If the item is already in the list, the items above it have their
  112 + # position adjusted accordingly.
107 113 def move_to_top
108 114 return unless in_list?
109 115 acts_as_list_class.transaction do
@@ -111,31 +117,36 @@ def move_to_top
111 117 assume_top_position
112 118 end
113 119 end
114   -
  120 +
115 121 def remove_from_list
116 122 decrement_positions_on_lower_items if in_list?
117 123 end
118 124
  125 + # Increase the position of this item without adjusting the rest of the list.
119 126 def increment_position
120 127 return unless in_list?
121 128 update_attribute position_column, self.send(position_column).to_i + 1
122 129 end
123 130
  131 + # Decrease the position of this item without adjusting the rest of the list.
124 132 def decrement_position
125 133 return unless in_list?
126 134 update_attribute position_column, self.send(position_column).to_i - 1
127 135 end
128 136
  137 + # Return true if this object is the first in the list.
129 138 def first?
130 139 return false unless in_list?
131 140 self.send(position_column) == 1
132 141 end
133 142
  143 + # Return true if this object is the last in the list.
134 144 def last?
135 145 return false unless in_list?
136 146 self.send(position_column) == bottom_position_in_list
137 147 end
138 148
  149 + # Return the next higher item in the list.
139 150 def higher_item
140 151 return nil unless in_list?
141 152 acts_as_list_class.find(:first, :conditions =>
@@ -143,6 +154,7 @@ def higher_item
143 154 )
144 155 end
145 156
  157 + # Return the next lower item in the list.
146 158 def lower_item
147 159 return nil unless in_list?
148 160 acts_as_list_class.find(:first, :conditions =>
1  activerecord/lib/active_record/associations.rb
@@ -1147,6 +1147,7 @@ def construct_finder_sql_with_included_associations(options, join_dependency)
1147 1147 add_conditions!(sql, options[:conditions], scope)
1148 1148 add_limited_ids_condition!(sql, options, join_dependency) if !using_limitable_reflections?(join_dependency.reflections) && ((scope && scope[:limit]) || options[:limit])
1149 1149
  1150 + sql << "GROUP BY #{options[:group]} " if options[:group]
1150 1151 sql << "ORDER BY #{options[:order]} " if options[:order]
1151 1152
1152 1153 add_limit!(sql, options, scope) if using_limitable_reflections?(join_dependency.reflections)
4 activerecord/test/associations_test.rb
@@ -1619,4 +1619,8 @@ def test_updating_attributes_on_rich_associations_with_limited_find
1619 1619 def test_join_table_alias
1620 1620 assert_equal 3, Developer.find(:all, :include => {:projects => :developers}, :conditions => 'developers_projects_join.joined_on IS NOT NULL').size
1621 1621 end
  1622 +
  1623 + def test_join_with_group
  1624 + assert_equal 2, Developer.find(:all, :include => {:projects => :developers}, :conditions => 'developers_projects_join.joined_on IS NOT NULL', :group => "developers.name").size
  1625 + end
1622 1626 end

0 comments on commit b272100

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