Created
September 16, 2011 15:52
-
-
Save roykolak/1222415 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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