Reputation: 1310
I am implementing a multi-users website. They can create "items". When a new user registers and creates his first item I want it to have an ID of 1, not 2728 (its ID from DB).
So I need some kind of mapping? E.g. | real_item_id | fake_item_id | 2728 1
So for each Account I will have a table with fake_id starting from 1 and incrementing every time a User creates an item?
Maybe there is another, better approach?
Upvotes: 1
Views: 250
Reputation: 90
Simply create a table to track items created by each User and keep on increasing Items count whenever user creates new item and update increased items id into main table(more easier) or Another approched will be keep two column on your table one User ID and another one for Items Id which will get increamented id on each new item inserted by particular user by checking last item inserted by particular user.
Upvotes: 1
Reputation: 854
I think you don't need any new table for this. Just add a column fake_id
into items
table and scope it with user_id for uniqueness.
Also create a custom validation method in model to assign fake_id
to Item while creating. Thanks
Upvotes: 1