zapletnev
zapletnev

Reputation: 503

Efficient way to store reorderable items in a database for multiple users

A have list of items created by users, this items can be reordered by them. Efficient data structure for this described here.

But in my case users can share their items between each other and reorder them as well. So it means that we need to store elements order for each user. What is a best database structure for this? I can see only one way: create duplicate item and store reference to the origin item, but it look odd for me.

Upvotes: 0

Views: 248

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1270191

You want an association/junction table. This would have at least three columns:

  • UserId
  • ItemId
  • Ordering

(And you might have additional columns, such as an auto-incremented primary key and a creation dat.)

The first two should be foreign references to a users and items table respectively.

Upvotes: 4

Related Questions