in the class "Problem":
belongs_to :project before_validation( :on => :create ) do self.issue_number = self.project.issues.collect { | issue | issue.issue_number }.max + 1 end
(or so) - essentially, before creating a new object, find the maximum number of problems associated with the project of the problem, increase this value and use it for the new problem number ...
source share