app/models/taxonomy_term.rb in daengine-0.3.8.2 vs app/models/taxonomy_term.rb in daengine-0.3.8.3

- old
+ new

@@ -27,6 +27,21 @@ def self.label_for_term(term_id) where(term_id: term_id).try(:first).try(:label) if term_id end + def ancestor?(term) + if(parent_term) + (parent_term == term) or parent_term.ancestor?(term) + else + false + end + end + + def descendant?(term) + # accept either an ID string or a term + term_id = term.is_a?(String) ? term : term.try(:term_id) + # loop thru child terms and look for the id + child_term_ids.index(term_id) or child_terms.detect {|c| c.descendant? term_id } + end + end