Class: Spree::VariantMedia
- Inherits:
-
Object
- Object
- Spree::VariantMedia
- Defined in:
- app/models/spree/variant_media.rb
Overview
FK column is media_id, matching Spree::Media and its table. The :asset
association name stays readable until 6.3.
Class Method Summary collapse
-
.resolve_variant_ids(product, variant_ids) ⇒ Object
Resolves an array of variant identifiers (prefixed ids or raw ids) to the numeric ids of variants that belong to
product.
Class Method Details
.resolve_variant_ids(product, variant_ids) ⇒ Object
Resolves an array of variant identifiers (prefixed ids or raw ids) to the
numeric ids of variants that belong to product. Anything else — bad
prefix, foreign product, garbage — is dropped. This is the security
boundary used by Spree::Media#variant_ids=, so callers (forms, API params)
can't link assets to variants from another product.
20 21 22 23 24 25 26 27 28 29 |
# File 'app/models/spree/variant_media.rb', line 20 def self.resolve_variant_ids(product, variant_ids) ids = Array(variant_ids).reject(&:blank?) return [] if ids.empty? product.variants.filter_map do |variant| token = variant.id.to_s prefixed = variant.prefixed_id variant.id if ids.any? { |id| id.to_s == token || id == prefixed } end end |