Module: Traits::Model::Querying

Included in:
Traits::Model
Defined in:
lib/traits/model/querying.rb

Instance Method Summary collapse

Instance Method Details

#arelObject



20
21
22
# File 'lib/traits/model/querying.rb', line 20

def arel
  active_record.arel_table
end

#connectionObject



24
25
26
# File 'lib/traits/model/querying.rb', line 24

def connection
  active_record.connection
end

#primary_key_attributeObject



16
17
18
# File 'lib/traits/model/querying.rb', line 16

def primary_key_attribute
  @pk_attr ||= attributes[primary_key_name]
end

#primary_key_nameObject



7
8
9
10
11
12
13
14
# File 'lib/traits/model/querying.rb', line 7

def primary_key_name
  # Sometimes table doesn't have primary key.
  # This might be many-to-many tables (HABTM).
  @pk_name ||= begin
    pk = active_record.primary_key
    pk.kind_of?(String) ? pk.to_sym : pk
  end
end

#quoted_table_nameObject



32
33
34
# File 'lib/traits/model/querying.rb', line 32

def quoted_table_name
  @quote_table_name ||= connection.quote_table_name(active_record.table_name)
end

#table_nameObject



28
29
30
# File 'lib/traits/model/querying.rb', line 28

def table_name
  @table_name ||= active_record.table_name
end

#to_hashObject



36
37
38
39
40
41
42
43
# File 'lib/traits/model/querying.rb', line 36

def to_hash
  super.merge!(
    table_name:        table_name,
    quoted_table_name: quoted_table_name,
    polymorphic_type:  polymorphic_type,
    primary_key_name:  primary_key_name
  )
end