Jump to content

The ultimate community for Ruby on Rails developers.


Photo

Best way to deal with database items with variables


  • Please log in to reply
2 replies to this topic

#1 DvDj

DvDj

    Signalman

  • Members
  • 20 posts
  • LocationUnited Kingdom

Posted 28 June 2014 - 10:35 PM

I am looking for some advice on how best to approach creating a database with products that are available in different colours.

 

There are a few hundred products that need to be stored in a database, each of which is made up of a six numbered item code. For example 198403, the first four digits 1984 are for the item itself and then the last two digits, 03 in this case, reference the colour the item is.  Items can be multiple colours; 198403 = Black, 198405 = Red.

 

I would like advice on how best to create this, do I create one database listing the first four digits (i.e the item itself) in one database and then reference the colours in another database or just have one database that lists each item and its colour?

 

If users search for an item just typing in the first four digits, then I want to be able to return back to them the item and show to them all the available colours.  if however the user types in all six digits then only the item in the colour requested is initially displayed.

 

Hope that all makes enough sense for you to give me your thoughts.

 



#2 UncleCid

UncleCid

    Passenger

  • Members
  • 1 posts

Posted 04 July 2014 - 08:46 AM

I would like advice on how best to create this, do I create one database listing the first four digits (i.e the item itself) in one database and then reference the colours in another database or just have one database that lists each item and its colour?
This will surely work.

 

And then for the item, one of the columns could be an array of the available colors.  This will save time, at least, but someone may suggest a different approach.  



#3 DvDj

DvDj

    Signalman

  • Members
  • 20 posts
  • LocationUnited Kingdom

Posted 04 July 2014 - 10:04 AM   Best Answer

Hi UncleCid,

 

'Guard', just educated me on creating a field containing an array which is looking like the best answer for me :)

 

Thank you for your time and help, much appreciated.

 

Stuart






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users