Skip to content

Instantly share code, notes, and snippets.

@ankit8898
Created June 28, 2013 10:16
Show Gist options
  • Save ankit8898/5883757 to your computer and use it in GitHub Desktop.
Save ankit8898/5883757 to your computer and use it in GitHub Desktop.
Alternative for awesome_nested_set self_and_descendants and descendants. Basically with the idea of hitting the sql that are fired by the nested_set helper
class Group < ActiveRecord::Base
acts_as_nested_set
def self_and_descendants_hashed
ActiveRecord::Base.connection.select_all("SELECT * FROM groups WHERE lft >= #{self.lft} AND rgt <= #{self.rgt} order by lft")
end
def descendants_hashed
ActiveRecord::Base.connection.select_all("SELECT * FROM groups WHERE lft >= #{self.lft} AND lft < #{self.rgt} AND id != 1 ORDER BY lft")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment