Sha256: d6d23545a31f589cf78bc3851a27d21f3ede22996a3bb942a3e02016e13925e8

Contents?: true

Size: 697 Bytes

Versions: 9

Compression:

Stored size: 697 Bytes

Contents

# frozen_string_literal: true

module Motor
  class Query < ::Motor::ApplicationRecord
    audited

    belongs_to :author, polymorphic: true, optional: true

    has_many :taggable_tags, as: :taggable, dependent: :destroy
    has_many :tags, through: :taggable_tags, class_name: 'Motor::Tag'
    has_many :alerts, dependent: :destroy

    serialize :preferences, HashSerializer

    scope :active, -> { where(deleted_at: nil) }

    def result(variables_hash = {})
      result = Motor::Queries::RunQuery.call(self, variables_hash: variables_hash)
      column_names = result.columns.pluck(:name)

      result.data.map { |row| column_names.zip(row).to_h }
    end
    alias run result
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
motor-admin-0.1.49 app/models/motor/query.rb
motor-admin-0.1.48 app/models/motor/query.rb
motor-admin-0.1.47 app/models/motor/query.rb
motor-admin-0.1.46 app/models/motor/query.rb
motor-admin-0.1.44 app/models/motor/query.rb
motor-admin-0.1.43 app/models/motor/query.rb
motor-admin-0.1.42 app/models/motor/query.rb
motor-admin-0.1.41 app/models/motor/query.rb
motor-admin-0.1.40 app/models/motor/query.rb