Module: ActiveRecordExtension::ClassMethods
- Defined in:
- lib/active_record_extension.rb
Overview
add your static(class) methods here
Instance Method Summary collapse
- #belongs_to_field(field) ⇒ Object
- #belongs_to_field?(field) ⇒ Boolean
- #belongs_to_field_by_name(name) ⇒ Object
- #belongs_to_fields ⇒ Object
-
#many_to_many_associated_tables ⇒ Object
OData does not allow creating an entry for a table that is used in a many to many joining table.
- #many_to_many_associated_tables=(value) ⇒ Object
-
#odata_field(field, options) ⇒ Object
In some cases the odata field name is different than the database field name.
- #odata_field_value(crm_key) ⇒ Object
-
#odata_table_reference ⇒ Object
If odata refers to table differently than table name when using associations, you can use this method.
- #odata_table_reference=(value) ⇒ Object
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
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_field_by_name(name) ⇒ Object
72 73 74 75 |
# File 'lib/active_record_extension.rb', line 72 def belongs_to_field_by_name(name) @belongs_to_fields ||= belongs_to_fields @belongs_to_fields.select{|f| f.name.to_s == name}.first end |
#belongs_to_fields ⇒ Object
77 78 79 80 |
# File 'lib/active_record_extension.rb', line 77 def belongs_to_fields associations = reflect_on_all_associations associations.select { |a| a.macro == :belongs_to } end |
#many_to_many_associated_tables ⇒ Object
OData does not allow creating an entry for a table that is used in a many to many joining table. You must associate tables together. If a table uses this field, it indicates its a joining many to many table. An array of the 2 associated tables, eg [Table1, Table2]
94 95 96 |
# File 'lib/active_record_extension.rb', line 94 def many_to_many_associated_tables @many_to_many_associated_tables end |
#many_to_many_associated_tables=(value) ⇒ Object
98 99 100 |
# File 'lib/active_record_extension.rb', line 98 def many_to_many_associated_tables=(value) @many_to_many_associated_tables = value end |
#odata_field(field, options) ⇒ Object
In some cases the odata field name is different than the database field name. This method is used for this mapping
103 104 105 106 |
# File 'lib/active_record_extension.rb', line 103 def odata_field(field, ) @odata_property_key ||= {} @odata_property_key[field] = [:crm_key] end |
#odata_field_value(crm_key) ⇒ Object
108 109 110 111 |
# File 'lib/active_record_extension.rb', line 108 def odata_field_value(crm_key) @odata_property_key ||= {} @odata_property_key[crm_key] end |
#odata_table_reference ⇒ Object
If odata refers to table differently than table name when using associations, you can use this method
83 84 85 |
# File 'lib/active_record_extension.rb', line 83 def odata_table_reference @odata_table_reference end |
#odata_table_reference=(value) ⇒ Object
87 88 89 |
# File 'lib/active_record_extension.rb', line 87 def odata_table_reference=(value) @odata_table_reference = value end |