I have a function in my model that changes is as follows:
def compare
self.dirty = 1 if self.dirty == 0
compare_recursive(0, MergeDigestTree.all)
self.dirty = 0;
end
Do I have to call self.save or is it fine like this
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Your question is open to two interpretations:
Do you have to call
self.saveso the record is saved at this point? yes, because an attribute assignation does not commit the change to the database.Are you forced to call
self.saveand thus save the record? no. It’s ok for a method to change the instance and do not save it. I usually prefer this one, as you give more freedom to the caller.Whatever the case, document the method accordingly.