Sha256: 2c150fc655f7c3924f4cb19048d5fd805e65636cb4b88399d02b66cce399e480

Contents?: true

Size: 1.66 KB

Versions: 65

Compression:

Stored size: 1.66 KB

Contents

module ForestLiana
  module QueryHelper
    def self.get_one_associations(resource)
      associations = SchemaUtils.one_associations(resource)
        .select do |association|
          if SchemaUtils.polymorphic?(association)
            SchemaUtils.polymorphic_models(association).all? { |model| SchemaUtils.model_included?(model) }
          else
            SchemaUtils.model_included?(association.klass)
          end
        end

      associations
    end

    def self.get_one_association_names_symbol(resource)
      self.get_one_associations(resource).map(&:name)
    end

    def self.get_one_association_names_string(resource)
      self.get_one_associations(resource).map { |association| association.name.to_s }
    end

    def self.get_tables_associated_to_relations_name(resource)
      tables_associated_to_relations_name = {}
      associations_has_one = self.get_one_associations(resource)

      associations_has_one.each do |association|
        if SchemaUtils.polymorphic?(association)
          SchemaUtils.polymorphic_models(association).each do |model|
            if tables_associated_to_relations_name[model.table_name].nil?
              tables_associated_to_relations_name[model.table_name] = []
            end
            tables_associated_to_relations_name[model.table_name] << association.name
          end
        else
          if tables_associated_to_relations_name[association.try(:table_name)].nil?
            tables_associated_to_relations_name[association.table_name] = []
          end
          tables_associated_to_relations_name[association.table_name] << association.name
        end
      end

      tables_associated_to_relations_name
    end
  end
end

Version data entries

65 entries across 65 versions & 1 rubygems

Version Path
forest_liana-9.11.1 app/helpers/forest_liana/query_helper.rb
forest_liana-9.11.0 app/helpers/forest_liana/query_helper.rb
forest_liana-9.10.6 app/helpers/forest_liana/query_helper.rb
forest_liana-9.10.5 app/helpers/forest_liana/query_helper.rb
forest_liana-9.10.4 app/helpers/forest_liana/query_helper.rb
forest_liana-9.10.3 app/helpers/forest_liana/query_helper.rb
forest_liana-9.10.2 app/helpers/forest_liana/query_helper.rb
forest_liana-9.10.1 app/helpers/forest_liana/query_helper.rb
forest_liana-9.10.0 app/helpers/forest_liana/query_helper.rb
forest_liana-9.9.1 app/helpers/forest_liana/query_helper.rb
forest_liana-9.9.0 app/helpers/forest_liana/query_helper.rb
forest_liana-9.8.0 app/helpers/forest_liana/query_helper.rb
forest_liana-9.7.0 app/helpers/forest_liana/query_helper.rb
forest_liana-9.6.4 app/helpers/forest_liana/query_helper.rb
forest_liana-9.6.3 app/helpers/forest_liana/query_helper.rb
forest_liana-9.6.0 app/helpers/forest_liana/query_helper.rb
forest_liana-9.5.7 app/helpers/forest_liana/query_helper.rb
forest_liana-9.5.6 app/helpers/forest_liana/query_helper.rb
forest_liana-9.5.5 app/helpers/forest_liana/query_helper.rb
forest_liana-9.5.4 app/helpers/forest_liana/query_helper.rb