I have an Orders table in a SQL database (PostgreSQL if it matters, and Rails 4.04) and I want the column "number" in the orders table to kind of shadow the id column. In other words I want an automatic sequential field but I want it to be in the form:
Order::PRODUCT_NU_PREFIX + ((Order::STARTING_PRODUCT_NO + order.id).to_s)
So that if I set
PRODUCT_NU_PREFIX = 'PE' and
STARTING_PRODUCT_NO = '11681'
Then the first order I create will have a product number:
KB11682 and then
KB11683
SHould I do this purely in PostgreSQL or is there a good way to do it in Rails? Keep in mind I'll need to know what the latest Order.id is when an order comes in because when I save that new record I want that field to get saved correctly.