Class: MageRecord::EavRecord

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/magerecord/eav_record.rb

Direct Known Subclasses

Address, Customer, Product

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/magerecord/eav_record.rb', line 27

def method_missing(meth, *args, &block)
  eav = get_eav_records(meth)

  if eav.count > 0
    # return value of Magento EAV attribute if available
    eav.first
  else
    # call superclass's method_missing method
    # or risk breaking Ruby's method lookup
    super
  end
end

Class Method Details

.eav_attributesObject

return the full list of EAV attributes available for this entity type



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/magerecord/eav_record.rb', line 8

def self.eav_attributes
  conn = connection

  # note: select_values returns just one value from a single db column
  conn.select_values <<-RAWSQL.strip_heredoc
    SELECT attribute_code
    FROM eav_entity_type, eav_attribute
    WHERE eav_entity_type.entity_type_code = #{conn.quote(eav_prefix)}
      AND eav_attribute.entity_type_id = eav_entity_type.entity_type_id
  RAWSQL
end

.eav_prefixObject

returns the Magento EAV DB table prefix for this entity type



22
23
24
# File 'lib/magerecord/eav_record.rb', line 22

def self.eav_prefix
  table_name.gsub(/_entity$/, '')
end

Instance Method Details

#respond_to?(meth, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/magerecord/eav_record.rb', line 41

def respond_to?(meth, include_private = false)
  super || (get_eav_records(meth).count > 0)
end