Skip to content

Instantly share code, notes, and snippets.

@roykolak
Created September 16, 2011 15:52
Show Gist options
  • Save roykolak/1222415 to your computer and use it in GitHub Desktop.
Save roykolak/1222415 to your computer and use it in GitHub Desktop.
class Fitting < ActiveRecord::Base
validates_presence_of :user, :timestamp, :specialist
validates_presence_of :left_ear, :if => Proc.new { right_ear.blank? }
validates_presence_of :right_ear, :if => Proc.new { left_ear.blank? }
belongs_to :user
belongs_to :left_ear, :class_name => 'Product', :foreign_key => 'left_ear_id'
belongs_to :right_ear, :class_name => 'Product', :foreign_key => 'right_ear_id'
belongs_to :specialist
has_many :programs, :order => 'slot ASC'
def has_customized_programs?
customized_programs = programs.select {|program| program.is_customized?}
customized_programs.length > 0 ? true : false
end
def products
[right_ear, left_ear]
end
def unique_products
products.uniq
end
def initial?
user.fittings.count == 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment