public
Description: has_adjacent_finders allows you to find rows that are adjacent to other records in your database.
Homepage: http://aktagon.com/projects/rails/has_adjacent_finders
Clone URL: git://github.com/christianhellsten/has_adjacent_finders.git
name age message
file LICENSE Tue Oct 21 09:25:04 -0700 2008 first commit [christianhellsten]
file README.textile Tue Oct 21 09:31:12 -0700 2008 Fixed docs and typo. [christianhellsten]
file init.rb Tue Oct 21 09:25:04 -0700 2008 first commit [christianhellsten]
directory lib/ Tue Oct 21 09:31:12 -0700 2008 Fixed docs and typo. [christianhellsten]
directory test/ Tue Oct 21 09:25:04 -0700 2008 first commit [christianhellsten]
README.textile

has-adjacent-finders

This plugin allows you to find rows adjacent to an arbitrary row by adding the following methods to ActiveRecord models:

  • find_next_row - find record to the right of current record
  • find_previous_row - find record to the left of current record
  • find_next_rows - find records to the right of current record
  • find_previous_rows - find records to the left of current record
  • find_adjacent_rows - find records to the right and left of current record
    ***************************************************************************

Usage

	
class Product < ActiveRecord::Base
	has_adjacent_finders
end

@product = Product.find(1)

@product.find_next_row
@product.find_previous_row
@product.find_adjacent_rows
	

Advanced usage

	
@product = Product.find(1)

@product.find_next_row({:conditions => "category_id = #{@product.category_id}"})
@product.find_previous_row({:conditions => "category_id = #{@product.category_id}"})
@product.find_adjacent_rows({:left => 2, :right => 3}, {:conditions => "category_id = #{@product.category_id}", :order => 'id', :include => :shop})
	

Author

Christian Hellsten (Aktagon Ltd.)