Module: Traits::Model::Querying
- Included in:
- Traits::Model
- Defined in:
- lib/traits/model/querying.rb
Instance Method Summary collapse
- #arel ⇒ Object
- #connection ⇒ Object
- #primary_key_attribute ⇒ Object
- #primary_key_name ⇒ Object
- #quoted_table_name ⇒ Object
- #table_name ⇒ Object
- #to_hash ⇒ Object
Instance Method Details
#arel ⇒ Object
20 21 22 |
# File 'lib/traits/model/querying.rb', line 20 def arel active_record.arel_table end |
#connection ⇒ Object
24 25 26 |
# File 'lib/traits/model/querying.rb', line 24 def connection active_record.connection end |
#primary_key_attribute ⇒ Object
16 17 18 |
# File 'lib/traits/model/querying.rb', line 16 def primary_key_attribute @pk_attr ||= attributes[primary_key_name] end |
#primary_key_name ⇒ Object
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_name ⇒ Object
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_name ⇒ Object
28 29 30 |
# File 'lib/traits/model/querying.rb', line 28 def table_name @table_name ||= active_record.table_name end |
#to_hash ⇒ Object
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 |