Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question
1  
you are talking about the 5th Normal Form... I suggest you read up on all of them, and learn when which is required en.wikipedia.org/wiki/Fifth_normal_form –  AK_ Feb 6 at 16:20
    
Also worth pointing out that relationship database design is very different to object orientated design. Using table records and objects interchangeably is incorrect. A lot of web frameworks confuse the matter by having a table record hold the data for a single object, but this is a convenience, it shouldn't be understood as relational databases being anything to do with objects and classes. –  Cormac Mulhall Feb 10 at 13:44
    
Can you recommend any further ressources on that matter? –  Isaac Feb 10 at 15:00

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
    
That is definitely smarter, thanks. I will have to think about how I create a SONG entity from a recording that might be incorrectly tagged, but that should be doable. Maybe the SONG just needs an id anyway. –  Isaac Feb 6 at 17:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.