[LRUG] Best way to implement an increasing number?

Andrew Stewart boss at airbladesoftware.com
Fri Apr 19 02:25:28 PDT 2013


On 19 Apr 2013, at 11:10, Jonathon Horsman wrote:
> Any reason not to use
> 
> before_validation :set_code
> 
> rather than
> 
> after_create :set_code
> 
> and set_code method merely sets the value on the object rather than hit the database a second time?

According to my git history I introduced that line 4 years, 8 months ago.  Looking at it now, I think I could use `before_validation` instead of `after_create`.

I see how that would eliminate a third write to the database (update A, insert B instead of insert B, update A, update B) – but wouldn't it still leave open the possibility of deadlocks on A?

Thanks,
Andy


More information about the Chat mailing list