class Donator < ActiveRecord::Base
  has_one :particular, :as => :owner
  
  accepts_nested_attributes_for :particular
  validates :nuc, :presence => true, :uniqueness => true
  
  has_many :donator_transactions
  
  before_validation do
    if !self.nuc?
      if last_nuc = Donator.order("nuc DESC").first
        self.nuc = last_nuc.nuc.to_i + 1
      else
        self.nuc = 1
      end
    end
      
  end

end
