Class: Comee::Core::SupplierAddress
- Inherits:
-
Address
- Object
- ActiveRecord::Base
- ApplicationRecord
- Address
- Comee::Core::SupplierAddress
- Defined in:
- app/models/comee/core/supplier_address.rb
Constant Summary
Constants inherited from Address
Address::ADDRESS_TYPES, Address::BASIC_ADDRESS, Address::DELIVERY_ADDRESS, Address::INVOICING_ADDRESS, Address::SHIPPING_ADDRESS
Instance Method Summary collapse
Instance Method Details
#validate_default ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'app/models/comee/core/supplier_address.rb', line 8 def validate_default return unless supplier && address_type && default default_count = if new_record? SupplierAddress.where(address_type: address_type, supplier: supplier, default: true).count else SupplierAddress.where(address_type: address_type, supplier: supplier, default: true) .where.not(id: id).count end return if default_count.zero? errors.add(:default, "cannot be set to true. There is already a default address for this supplier and address type.") end |