Class: Arel::Visitors::ToSql

Inherits:
Object
  • Object
show all
Defined in:
lib/arel_columns_hash/to_sql.rb

Instance Method Summary collapse

Instance Method Details

#column_for(attr) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/arel_columns_hash/to_sql.rb', line 2

def column_for attr
  return unless attr
  name     = attr.name.to_s
  relation = attr.relation

  if has_columns_hash? relation
    relation.engine.columns_hash[name]
  elsif table_exists? relation.table_name
    column_cache(relation.table_name)[name]
  else
    nil
  end
end

#has_columns_hash?(relation) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/arel_columns_hash/to_sql.rb', line 16

def has_columns_hash?(relation)
  relation.respond_to?(:engine) && relation.engine.respond_to?(:columns_hash)
end