Simplify customer model requiring enterprise

This commit is contained in:
Maikel Linke
2022-09-07 14:48:43 +10:00
parent be31b9a897
commit aec28e0807

View File

@@ -14,7 +14,7 @@ class Customer < ApplicationRecord
searchable_attributes :first_name, :last_name, :email, :code
belongs_to :enterprise
belongs_to :enterprise, optional: false
belongs_to :user, class_name: "Spree::User"
has_many :orders, class_name: "Spree::Order"
before_destroy :update_orders_and_delete_canceled_subscriptions
@@ -33,7 +33,6 @@ class Customer < ApplicationRecord
validates :code, uniqueness: { scope: :enterprise_id, allow_nil: true }
validates :email, presence: true, 'valid_email_2/email': true,
uniqueness: { scope: :enterprise_id, message: I18n.t('validation_msg_is_associated_with_an_exising_customer') }
validates :enterprise, presence: true
scope :of, ->(enterprise) { where(enterprise_id: enterprise) }