Class: ProductFeatureValue
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ProductFeatureValue
- Defined in:
- app/models/product_feature_value.rb
Overview
create_table :product_feature_values do |t|
t.string :value
t.string :internal_identifier
t.string :external_identifier
t.string :external_id_source
t.string :description
t.
end
add_index :product_feature_values, :internal_identifier, name: ‘product_ft_vals_iid_idx’
Class Method Summary collapse
Class Method Details
.find_or_create(internal_identifier, description, product_feature_type = nil) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/models/product_feature_value.rb', line 23 def self.find_or_create(internal_identifier, description, product_feature_type=nil) product_feature_value = ProductFeatureValue.joins(:product_feature_type_product_feature_values) .where(internal_identifier: internal_identifier).readonly(false).first unless product_feature_value product_feature_value = ProductFeatureValue.create(description: description, internal_identifier: internal_identifier) end if product_feature_type unless product_feature_value.product_feature_types.collect(&:id).include?(product_feature_type.id) product_feature_value.product_feature_types << product_feature_type product_feature_value.save end end product_feature_value end |