lib/fertile_forest/modules/utilities.rb
#
# Resolve node from Entity|int params.
#
# @param nodes [ActiveRecord::Base|Integer|Array] To identify the nodes.
# @param refresh [Boolean] true:Refind each Entity by id.
# @return [ActiveRecord::Base|Hash] When nodes is array, return value is hash.
#
Resolve node from Entity|int params.
Resolve node from Entity|int params .
def ff_resolve_nodes(nodes, refresh = false)
            return nodes if nodes.blank?
            is_plural = nodes.is_a?(Array)
            nodes = [nodes] unless is_plural
            res_entities = {}
            refind_ids   = []
            nodes.each do |item|
              is_node = item.is_a?(ActiveRecord::Base)
              if is_node
                the_id = item.id
              else
                the_id = item.to_i
              end
              if !is_node || refresh
                refind_ids << the_id
                res_entities[the_id] = nil
              else
                res_entities[the_id] = item
              end
            end
            if refind_ids.present?
              aim_query = ff_usual_conditions_scope(nil)
                .where(id: refind_ids)
                .ff_required_columns_scope()
              aim_query.all.each do |node|
                res_entities[node.id] = node
              end
            end
             return value
            is_plural ? res_entities : res_entities.values.first
          end
def ff_resolve_nodes ( nodes , refresh = false ) return nodes if nodes . blank? is_plural = nodes . is_a? ( Array ) nodes = [ nodes ] unless is_plural res_entities = { } refind_ids = [ ] nodes . each do | item | is_node = item . is_a? ( ActiveRecord :: Base ) if is_node the_id = item . id else the_id = item . to_i end if ! is_node || refresh refind_ids << the_id res_entities [ the_id ] = nil else res_entities [ the_id ] = item end end if refind_ids . present? aim_query = ff_usual_conditions_scope ( nil ) . where ( id : refind_ids ) . ff_required_columns_scope ( ) aim_query . all . each do | node | res_entities [ node . id ] = node end end is_plural ? res_entities : res_entities . values . first end
Resolve node from Entity|int params.
Resolve node from Entity|int params .
## # get node orderd by id # # return value
When nodes is array, return value is hash.
When nodes is array return value is hash .
ActiveRecord::Base|Hash
nodes
To identify the nodes.
To identify the nodes .
refresh
Refind each Entity by id.
Refind each Entity by id .