views:

206

answers:

5

Example: I have two tables in my database called classA and classB, and one table called classA_classB. The last one just defined two int fields with foreign keys to link between classA and classB. So one classA can have many classB, and many classA can link with the same classB. Simple stuff, so far.

The problem is, in my special case, that I have a classA which wants to link to another classA. I.e. a Student links to his friends, who are Students as well.

So analogue to the technique above, I have: student and student_student. student_student has two fields: student_id, student_id. Problem: Can't have two fields with same name!

So I must call them like: master_student_id, slave_student_id.

But I don't like the terms "Master" and "Slave", because these are reminders to a bad time in our pasts. It may sound silly but I think it's not correct to keep these, at least from a moral perspective. I know it's just a part of modern computer science,... but....

how else could I call them?

parent and child maybe? Also i'm not sure if there's really one entity "the chief" while the other is "the employee"... Student and Student are not hierarchical. But then, again, lets imagine we had two classes "Teacher" and "Student". That would be a clear hierarchy. However, I need a neutral solution because my framework threads these 1:n relationships allways the same way.

+2  A: 

How about student_id and friend_id? There's no rule that says your foreign keys need to have the same column names as the primary key.

Doug R
Imagine a framework, where you create Entities in a web-backend. It auto-generates everything, and the framework can't know the context so detailed ;) ...that's why I need a "generic" solution.
openfrog
+3  A: 

Parent and Child or Owner and Child is the generally accepted solutions.

Kornel Kisielewicz
+1  A: 

What are the roles of the two students in the relationship? Friends? Mentors? Acquaintances? There are lots of possible roles they fill.

You can brainstorm a lot of roles that have asymmetric names.

friend, friend_of

mentor, mentored_by

referrer, referred_by

S.Lott
+1  A: 

related_id or associated_student_id would be my preference.

Phil Hannent
+1  A: 

Depends on rather the relationship (lets call it R) is symmetric. If so then person1, person2 is fine since R(person1, person2) = R(person2, person1). If they are not symmetric then the names should probably reflect an "agent and patient" relationship. So use a word to denote the agent and one to denote the patient, e.g. Befriender, Friend.

Rodrick Chapman