app/models/receipt.rb
# After save, updates any related field inside associated appointments.
# (for instance, if receipt.is_payed? => all appointments are assumed to be is_payed)
#
After save, updates any related field inside associated appointments.
After save updates any related field inside associated appointments .
def update_associated_appointments()
    if self.is_payed?                               
      Appointment.update_all( "is_payed=1", ['receipt_id = ?', self.id] ) if Appointment.new.attributes.include?('receipt_id')
    end
  end
def update_associated_appointments ( ) if self . is_payed? Appointment . update_all ( "is_payed=1" , [ 'receipt_id = ?' , self . id ] ) if Appointment . new . attributes . include? ( 'receipt_id' ) end end
After save, updates any related field inside associated appointments.
After save updates any related field inside associated appointments .
# When the receipt is flagged as 'payed', make sure all appointments are too: # [Steve, 20100501] The added check on the structure of Appointments is # needed to be compliant with the previous version of the structure of the # table, otherwise the migration from older DB version fails.