Sha256: 99268f4fe672f8350a368174ba7fbe4ab558d396791fbdecd6fbf60422068708
Contents?: true
Size: 812 Bytes
Versions: 29
Compression:
Stored size: 812 Bytes
Contents
module Comee module Core class ClientAddress < Address belongs_to :client validates :name, presence: true validate :validate_default def validate_default return unless client && address_type && default default_count = if new_record? ClientAddress.where(address_type: address_type, client: client, default: true).count else ClientAddress.where(address_type: address_type, client: client, 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 client and address type.") end end end end
Version data entries
29 entries across 29 versions & 1 rubygems