Module: ErpTechSvcs::Utils::DefaultNestedSetMethods::ClassMethods
- Defined in:
- lib/erp_tech_svcs/utils/default_nested_set_methods.rb
Instance Method Summary collapse
-
#find_by_ancestor_iids(iids) ⇒ Object
allows you to find a nested set element by the internal_identifiers in its ancestry for example, to find a GlAccount whose internal_identifier is “site_4”, and whose parent’s internal_identifier is “nightly_room_charge” and whose grandparent’s internal_identifier is “charge”, you would make this call: gl_account = GlAccount.find_by_iids([‘charge’, ‘nightly_room_charge’, “site_4”]).
- #find_children(parent_id = nil) ⇒ Object
- #find_roots ⇒ Object
Instance Method Details
#find_by_ancestor_iids(iids) ⇒ Object
allows you to find a nested set element by the internal_identifiers in its ancestry for example, to find a GlAccount whose internal_identifier is “site_4”, and whose parent’s internal_identifier is “nightly_room_charge”and whose grandparent’s internal_identifier is “charge”, you would make this call: gl_account = GlAccount.find_by_iids([‘charge’, ‘nightly_room_charge’, “site_4”])
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/erp_tech_svcs/utils/default_nested_set_methods.rb', line 45 def find_by_ancestor_iids(iids) return nil unless iids.is_a? Array node = nil iids.each do |iid| if (iid == iids.first) node = where("parent_id is null and internal_identifier = ?",iid).first else node = where("parent_id = ? and internal_identifier = ?",node.id,iid).first end return nil if node.nil? end return node end |
#find_children(parent_id = nil) ⇒ Object
36 37 38 |
# File 'lib/erp_tech_svcs/utils/default_nested_set_methods.rb', line 36 def find_children(parent_id = nil) parent_id.to_i == 0 ? self.roots : find(parent_id).children end |
#find_roots ⇒ Object
32 33 34 |
# File 'lib/erp_tech_svcs/utils/default_nested_set_methods.rb', line 32 def find_roots where("parent_id = nil") end |