These are chat archives for ManageIQ/manageiq/performance

21st
Sep 2016
Keenan Brock
@kbrock
Sep 21 2016 14:30

@NickLaMuro ok, instead of:

# VmOrTemplate.virtual_delegate :name, :to => :host, :prefix => true

# current
VmOrTemplate.select(:id, :name, :host_id, \
                    VmOrTemplate.arel_attribute(:host_name).as("host_name"))

# I want
VmOrTemplate.select(:id, :name, :host_id, :host_name)

PR to active record core was non-trivial

  • monkey patch AR (non-trivial)
  • override ApplicationRecord#select
  • write virtual_select or smart_select

The method is basically:

def virtual_select(*args)
  if args.first === Symbol
    args.first.map! { |r| virtual_attribute(r) ? arel_attribute(r).as(r.to_s) : r}
  select(*args)
  end
end