0

I find myself in a scenario:

a soundtrack can have multiple instruments.

Of that soundtrack there can be some versions with a different tone and versions without any instruments, or with a different tone and without any instruments.

In summary:

  • original soundtrack
  • soundtrack with different tones
  • soundtrack without any instruments
  • soundtrack with a different tone that without some instruments

To create a database I had thought to use Inheritance Mapping but I'm a beginner and do not know if it's the right way!

Tips? An idea on how to properly create ralations?

I thought:

soundtrack -> N:M <- Instrument

soundtrack -> ? -> Soundtrack_tone

soundtrack -> ? -> Soundtrack_any_instrument

But I stopped here for inexperience.

Lughino
  • 4,060
  • 11
  • 31
  • 61

1 Answers1

1

You don't need inheritance in your case. Inheritance is used for a "is a" relationship, i.e. Guitar -> Instrument. If I read your question it seems like you have basically 3 entities:

  • Soundtrack
  • Instrument
  • Tone

A soundtrack may have multiple instrument and multiple tones. The same instruments can be associated with various soundtracks, and the same goes for tones. So you need to create 2 associations:

  • Soundtrack -> Instrument (ManyToMany)
  • Soundtrack -> Tone (ManyToMany)
Bram Gerritsen
  • 7,178
  • 4
  • 35
  • 45
  • Thank you for the answer. My idea of using inheritance mapping is because there is the original soundtrack, and then there may be different versions of the soundtrack that are no instruments or in different colors, or both. So I can not use the soundtrack directly affiliated with tones and instruments. – Lughino Jul 13 '13 at 20:05
  • 1
    Ok I understand. I would simply create a SoundtrackVersion entity which have all the associations to the tones / instruments. Now create a oneToMany association from Soundtrack -> SoundtrackVersion. Now you have one instance of your original soundtracks in `Soundtrack` and retrieve all the versions, `Soundtrack->getVersions()`. – Bram Gerritsen Jul 13 '13 at 20:08