Class: Spree::VariantMedia
- Inherits:
-
Object
- Object
- Spree::VariantMedia
- Defined in:
- app/models/spree/variant_media.rb
Overview
FK column is ‘media_id` (not `asset_id`) to match the 6.0 rename Spree::Asset → Spree::Media. The `:asset` association name follows the current parent class; in 6.0 it renames to `:media` without a column change.
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::Asset#variant_ids=, so callers (forms, API params) can’t link assets to variants from another product.
22 23 24 25 26 27 28 29 30 31 |
# File 'app/models/spree/variant_media.rb', line 22 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 |