vinsol/spree_favorite_products

View on GitHub
app/models/spree/favorite.rb

Summary

Maintainability
A
0 mins
Test Coverage
module Spree
  class Favorite < ActiveRecord::Base
    with_options required: true do
      belongs_to :favoritable, polymorphic: true, counter_cache: :favorite_users_count
      belongs_to :user
    end

    validates :user_id, uniqueness: { scope: [:favoritable_id, :favoritable_type], message: Spree.t(:duplicate_favorite), allow_blank: true }
  end
end