I have seen elsewhere that it is a nice design to implement links between objects in a database as a separate object. This makes a clean way to have multiple objects of one class to be linked to an object of another class, as opposed to adding a “links” property to an object, which then gets populated with, say a CSV list of other objects that are linked.
Now I want to go through my music collection (MP3) and find differently encoded versions of the same recording (via audio fingerprinting – think of the same song ripped twice with a different bit rate for example). Now I am not sure how to design the link objects, since they link objects of the same class. I could just do something like
id songA songB
but then if I want to search for all matches for a particular song, I will have to go through both songA and songB to find possible links. Is there a smarter way to do this?
3
This doesn’t call for a linking entity (although they very useful for N:M relations and infinitely better than trying to cram a list of things into a single field or multiple fields!).
What you want is a SONG entity that can be referenced by multiple RECORDING entities. A SONG has a title, artist etc., while a RECORDING might have a bit rate, loudness, file date etc. The RECORDING would have a single foreign key to the SONG table. That’s how you express N:1 associations.
1