Module: Adocca::Acts::ActsAsFastNestedSet::InstanceMethods
- Defined in:
- lib/acts_as_fast_nested_set.rb
Instance Method Summary collapse
-
#descendants ⇒ Object
All our children and their children etc.
-
#destroy_descendants ⇒ Object
Destroys all children and their children etc.
-
#get_uniqueness_key ⇒ Object
Get a String suitable for using as a Memcache lock when creating a nodeid.
-
#kin ⇒ Object
Returns the entire thread.
- #level ⇒ Object
-
#siblings ⇒ Object
All nodes with the same parent.
Instance Method Details
#descendants ⇒ Object
All our children and their children etc
152 153 154 155 156 157 158 |
# File 'lib/acts_as_fast_nested_set.rb', line 152 def descendants cache_value("#{self.class.name}:#{self.id}:descendants") do self.class.find(:all, :conditions => ["node_id LIKE ? AND id != ?#{unique_with_and}", "#{self.node_id}%", self.id] + unique_params) end end |
#destroy_descendants ⇒ Object
Destroys all children and their children etc
137 138 139 140 141 142 |
# File 'lib/acts_as_fast_nested_set.rb', line 137 def destroy_descendants self.class.connection.delete( self.class.sanitizeSQL( ["DELETE FROM #{self.class.table_name} WHERE node_id LIKE ? AND id != ?#{unique_with_and}", "#{self.node_id}%", self.id] + unique_params)) end |
#get_uniqueness_key ⇒ Object
Get a String suitable for using as a Memcache lock when creating a nodeid.
116 117 118 119 120 121 122 123 124 125 |
# File 'lib/acts_as_fast_nested_set.rb', line 116 def get_uniqueness_key = self.class. uniqueness_key = "acts_as_fast_nested_set:nodeid_lock:" if [:uniqueness_scope] [:uniqueness_scope].each do |col| uniqueness_key << "#{self.send(col)}:" end end return uniqueness_key end |
#kin ⇒ Object
Returns the entire thread
129 130 131 132 133 |
# File 'lib/acts_as_fast_nested_set.rb', line 129 def kin self.class.find(:all, :conditions => ["node_id LIKE ?#{unique_with_and}", "#{root_id}.%"] + unique_params) end |
#level ⇒ Object
160 161 162 163 164 165 166 |
# File 'lib/acts_as_fast_nested_set.rb', line 160 def level if self.node_id.nil? 1 else self.node_id.count "." end end |
#siblings ⇒ Object
All nodes with the same parent
146 147 148 |
# File 'lib/acts_as_fast_nested_set.rb', line 146 def siblings self.class.find_all_by_parent_id(self.parent_id) end |