-1

I am struggling to figure out the relationship between ingredient and shampoo table. I have a join table between these tables called Shampoo_Ingredients. How do I figure out if these tables would be one-to-one, one-to-many, many-to-one, or many-to-many? Thanks for any help you can provide. This has been a really frustrating concept to me.

Image of DB

Shadow
  • 33,525
  • 10
  • 51
  • 64
Ice Wind
  • 11
  • 1
  • 5
  • I am thinking that the Shampoo table is ManyToMany because every shampoo has many times of ingredients. – Ice Wind Dec 27 '18 at 22:07
  • but then I start wondering what would the relationship be when talking about Ingredients table. – Ice Wind Dec 27 '18 at 22:08
  • Shampoo_Ingredients should be many to many, shampoo and Ingredients will one to many , company and shampoo will be one to one – Ramkumar Sambandam Dec 27 '18 at 22:21
  • It's simple: you just need to ask yourself these questions: Does a given shampoo have several ingredients, and is a given ingredient used in several shampoo? If yes, it's a ManyToMany. Does a shampoo have several ingredients, but each ingredient is used in only one champoo. If yes, it's a OneToMany. Does a shampoo have a single ingredient, and is an ingredient used by a single shampoo? If yes, it's a OneToOne. – JB Nizet Dec 27 '18 at 22:26
  • Thanks! Makes sense – Ice Wind Dec 27 '18 at 23:44

1 Answers1

0

A shampoo has many ingredients. An ingredient can be in many different shampoos.

So, you have a many-to-many using a join table Shampoo_ingredients.

Jackson Miller
  • 1,500
  • 1
  • 13
  • 23