Created
June 28, 2013 10:16
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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