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

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4543 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 f780bb8f
...@@ -77,7 +77,8 @@ module InstanceMethods ...@@ -77,7 +77,8 @@ module InstanceMethods
def insert_at(position = 1) def insert_at(position = 1)
insert_at_position(position) insert_at_position(position)
end end
# Swap positions with the next lower item, if one exists.
def move_lower def move_lower
return unless lower_item return unless lower_item
...@@ -87,6 +88,7 @@ def move_lower ...@@ -87,6 +88,7 @@ def move_lower
end end
end end
# Swap positions with the next higher item, if one exists.
def move_higher def move_higher
return unless higher_item return unless higher_item
...@@ -96,6 +98,8 @@ def move_higher ...@@ -96,6 +98,8 @@ def move_higher
end end
end end
# Move to the bottom of the list. If the item is already in the list, the items below it have their
# position adjusted accordingly.
def move_to_bottom def move_to_bottom
return unless in_list? return unless in_list?
acts_as_list_class.transaction do acts_as_list_class.transaction do
...@@ -104,6 +108,8 @@ def move_to_bottom ...@@ -104,6 +108,8 @@ def move_to_bottom
end end
end end
# Move to the top of the list. If the item is already in the list, the items above it have their
# position adjusted accordingly.
def move_to_top def move_to_top
return unless in_list? return unless in_list?
acts_as_list_class.transaction do acts_as_list_class.transaction do
...@@ -111,31 +117,36 @@ def move_to_top ...@@ -111,31 +117,36 @@ def move_to_top
assume_top_position assume_top_position
end end
end end
def remove_from_list def remove_from_list
decrement_positions_on_lower_items if in_list? decrement_positions_on_lower_items if in_list?
end end
# Increase the position of this item without adjusting the rest of the list.
def increment_position def increment_position
return unless in_list? return unless in_list?
update_attribute position_column, self.send(position_column).to_i + 1 update_attribute position_column, self.send(position_column).to_i + 1
end end
# Decrease the position of this item without adjusting the rest of the list.
def decrement_position def decrement_position
return unless in_list? return unless in_list?
update_attribute position_column, self.send(position_column).to_i - 1 update_attribute position_column, self.send(position_column).to_i - 1
end end
# Return true if this object is the first in the list.
def first? def first?
return false unless in_list? return false unless in_list?
self.send(position_column) == 1 self.send(position_column) == 1
end end
# Return true if this object is the last in the list.
def last? def last?
return false unless in_list? return false unless in_list?
self.send(position_column) == bottom_position_in_list self.send(position_column) == bottom_position_in_list
end end
# Return the next higher item in the list.
def higher_item def higher_item
return nil unless in_list? return nil unless in_list?
acts_as_list_class.find(:first, :conditions => acts_as_list_class.find(:first, :conditions =>
...@@ -143,6 +154,7 @@ def higher_item ...@@ -143,6 +154,7 @@ def higher_item
) )
end end
# Return the next lower item in the list.
def lower_item def lower_item
return nil unless in_list? return nil unless in_list?
acts_as_list_class.find(:first, :conditions => acts_as_list_class.find(:first, :conditions =>
......
...@@ -1147,6 +1147,7 @@ def construct_finder_sql_with_included_associations(options, join_dependency) ...@@ -1147,6 +1147,7 @@ def construct_finder_sql_with_included_associations(options, join_dependency)
add_conditions!(sql, options[:conditions], scope) add_conditions!(sql, options[:conditions], scope)
add_limited_ids_condition!(sql, options, join_dependency) if !using_limitable_reflections?(join_dependency.reflections) && ((scope && scope[:limit]) || options[:limit]) add_limited_ids_condition!(sql, options, join_dependency) if !using_limitable_reflections?(join_dependency.reflections) && ((scope && scope[:limit]) || options[:limit])
sql << "GROUP BY #{options[:group]} " if options[:group]
sql << "ORDER BY #{options[:order]} " if options[:order] sql << "ORDER BY #{options[:order]} " if options[:order]
add_limit!(sql, options, scope) if using_limitable_reflections?(join_dependency.reflections) add_limit!(sql, options, scope) if using_limitable_reflections?(join_dependency.reflections)
......
...@@ -1619,4 +1619,8 @@ def test_updating_attributes_on_rich_associations_with_limited_find ...@@ -1619,4 +1619,8 @@ def test_updating_attributes_on_rich_associations_with_limited_find
def test_join_table_alias def test_join_table_alias
assert_equal 3, Developer.find(:all, :include => {:projects => :developers}, :conditions => 'developers_projects_join.joined_on IS NOT NULL').size assert_equal 3, Developer.find(:all, :include => {:projects => :developers}, :conditions => 'developers_projects_join.joined_on IS NOT NULL').size
end end
def test_join_with_group
assert_equal 2, Developer.find(:all, :include => {:projects => :developers}, :conditions => 'developers_projects_join.joined_on IS NOT NULL', :group => "developers.name").size
end
end end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册