Module: ActiveRecordExtension::ClassMethods

Defined in:
lib/active_record_extension.rb

Overview

add your static(class) methods here

Instance Method Summary collapse

Instance Method Details

#belongs_to_field(field) ⇒ Object



67
68
69
70
# File 'lib/active_record_extension.rb', line 67

def belongs_to_field(field)
  @belongs_to_fields ||= belongs_to_fields
  @belongs_to_fields.select{|f| f.foreign_key == field}.first
end

#belongs_to_field?(field) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
65
# File 'lib/active_record_extension.rb', line 62

def belongs_to_field?(field)
  @belongs_to_fields ||= belongs_to_fields
  @belongs_to_fields.map(&:foreign_key).include?(field)
end

#belongs_to_fieldsObject



72
73
74
75
# File 'lib/active_record_extension.rb', line 72

def belongs_to_fields
  associations = reflect_on_all_associations
  associations.select { |a| a.macro == :belongs_to }
end

#odata_table_referenceObject

If odata referes to table differently than table name when using associations, you can use this method



78
79
80
# File 'lib/active_record_extension.rb', line 78

def odata_table_reference
  @odata_table_reference
end

#odata_table_reference=(value) ⇒ Object



82
83
84
# File 'lib/active_record_extension.rb', line 82

def odata_table_reference=(value)
  @odata_table_reference = value
end