Alvydas
Alvydas

Reputation: 354

Multiple one-to-one relationships in one entity

I'm designing a database for my game, and I've stumbled upon a small uncertainty.

My character should have two item containers - one for inventory and another one for items that are equipped.

I was wondering whether my solution is considered a bad practice and I should create another table called "character_container"?

Thanks,

Upvotes: 0

Views: 65

Answers (1)

Jemolah
Jemolah

Reputation: 2192

You have a user which can have multiple game_characters. So in DB you need a table game_character with a column "user_ref char(36) referencing user ( id )". Same goes for your inventory: In the DB you need a table "item" (or "container") with a reference to the game character: "game_char_ref char(36) referencing game_character ( id )". In Java its the other way round. You have a user with a collection of game_characters and a game_character with a collection of items. In a proper design, I suggest one table "Item" which contains all available items in the game with their attributes and one linking table "item4character" assigning an item to a game_character with count and attribute if its in the inventory, chest or worn.

Upvotes: 1

Related Questions