class LineOfWork < ActiveRecord::Base
  attr_accessible :budget_unit_id, :code, :digit, :name

  # Associations
  belongs_to :budget_unit
  has_many :institution_remunerations, dependent: :destroy

  # Validations
  validates :name, :code, presence: true
  validates :digit, numericality: true, allow_nil: true

  # Scopes
  scope :with_institution_remunerations, lambda { |institution_id| where("line_of_works.id in (select line_of_work_id from institution_remunerations where institution_id = #{institution_id})") }
end
