Skip to content

Instantly share code, notes, and snippets.

@hosiawak
Created January 8, 2009 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hosiawak/44656 to your computer and use it in GitHub Desktop.
Save hosiawak/44656 to your computer and use it in GitHub Desktop.
# New utility method to return ancestors and siblings and children
def ancestors_siblings_children
query = "#{scope_condition} AND (#{self[left_col_name]} BETWEEN #{left_col_name} AND #{right_col_name}) OR #{parent_col_name} = #{self.id} OR id = #{self.id}"
unless self[parent_col_name].nil?
query << " OR #{parent_col_name} = #{self[parent_col_name]}"
end
base_set_class.find(:all, :conditions => query, :order => left_col_name )
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment