First you'll need an unique index in posts with the user_id and
post_number to be sure that they'll not repeat. then you can just
create a before_create callback to define it:
First you'll need an unique index in posts with the user_id and
post_number to be sure that they'll not repeat. then you can just
create a before_create callback to define it:
If any existing posts were deleted then would this repeat already used
values? Also I think it is generating numbers based on the number of
posts for the current user which is not quite what was asked for.
hi,
in oracle we can use sequence.
in mysql use an autoincrement column, note that you have to save the
object so that it hits the database for the column to get updated.