mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Simplify customer model requiring enterprise
This commit is contained in:
@@ -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) }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user