Sha256: 44abd3d3264b24aee0a2e3f8a8ba9d0691e2b8aca4ad1e191f2330efe6525b6a

Contents?: true

Size: 845 Bytes

Versions: 25

Compression:

Stored size: 845 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

    attribute :preferences, default: -> { ActiveSupport::HashWithIndifferentAccess.new }
    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

ActiveSupport.run_load_hooks(:motor_query, Motor::Query)

Version data entries

25 entries across 25 versions & 4 rubygems

Version Path
motor-admin-pz-0.4.22 app/models/motor/query.rb
motor-admin-0.4.22 app/models/motor/query.rb
motor-admin-pz-0.4.21 app/models/motor/query.rb
motor-admin-0.4.21 app/models/motor/query.rb
motor-admin-0.4.20 app/models/motor/query.rb
motor-admin-0.4.19 app/models/motor/query.rb
motor-admin-pz-0.4.18.1 app/models/motor/query.rb
motor-admin-0.4.18 app/models/motor/query.rb
motor-admin-0.4.17 app/models/motor/query.rb
motor-alexandermohan-admin-panel-0.4.161 app/models/motor/query.rb
alexandermohan-admin-panel-0.4.161 app/models/motor/query.rb
motor-admin-0.4.16 app/models/motor/query.rb
motor-admin-pz-0.4.14 app/models/motor/query.rb
motor-admin-0.4.15 app/models/motor/query.rb
motor-admin-0.4.14 app/models/motor/query.rb
motor-admin-0.4.13 app/models/motor/query.rb
motor-admin-0.4.12 app/models/motor/query.rb
motor-admin-0.4.11 app/models/motor/query.rb
motor-admin-pz-0.4.10 app/models/motor/query.rb
motor-admin-0.4.10 app/models/motor/query.rb