Created
July 29, 2009 19:41
-
-
Save raymyers/158352 to your computer and use it in GitHub Desktop.
This file contains 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
def deep_attributes | |
attributes_to_copy(self).merge 'service_appointments_attributes'=>service_appointments.collect{|sa| | |
attributes_to_copy(sa).merge 'student_appointments_attributes'=>sa.student_appointments.collect{|std_a| | |
attributes_to_copy(std_a).merge 'student_appointment_goals_attributes'=>std_a.student_appointment_goals.collect{|sag| | |
attributes_to_copy(sag) | |
} | |
} | |
} | |
end | |
private | |
def attributes_to_copy(ar) | |
forbidden_keys = ['id', 'service_transaction_id', 'service_appointment_id', 'student_appointment_id'] | |
ar.attributes.reject do |k,v| | |
forbidden_keys.index(k) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment