i have a custom query which is getting max number from one of column.
I want to get that number increment by 1 and then save that in
different table. please refer following code:
def getmaxphasenumber(templaid)
self.find_by_sql(“select max(templateid) from templates”)
end
max= current_max ? current_max + 1 : 1
# Do whatever you want with the max here.
end
end
I wrap the maximum seach in a transaction to ensure the maximum KEEPS
BEING maximum till i end what i what to do with that maximum… do you
understand? (if someone saves a new record with a new maximum while i’m
working in the db my maximum could no longer be valid).
def getmaxphasenumber(templaid)
self.find_by_sql(“select max(templateid) from templates”)
end