class Customer < ApplicationRecord self.primary_key = "customer_id" before_create :generate_custom_id has_many :orders has_many :sales validates_presence_of :name, :contact_no validates :contact_no, uniqueness: true def lastest_invoices sales.where(:customer_id => self.id).order("created_at desc").limit(5) end private def generate_custom_id self.customer_id = SeedGenerator.generate_id(self.class.name, "CUS") end end