views:

213

answers:

7

What's a synonym for a "many-to-many" relationship? I've finished writing an object-relational mapper but I'm still stumped as to what to name the function that adds that relation.

addParent() and addChild() seemed quite logical for the many-to-one/one-to-many and addSuperclass() for one-to-one inheritance, but addManyToMany() would sound quite unintuitive to an object-oriented programmer. addSibling() or addCousin() doesn't really make sense either.

Any suggestions? And before you dismiss this as a non-programming question, please remember that consistent naming schemes and encapsulation are pretty integral to programming :)

A: 

CakePHP calls this a 'Has and belongs to many' association

http://book.cakephp.org/view/85/Saving-Related-Model-Data-HABTM

Brendan Heywood
Sorry, what I meant was something that would be meaningful to someone who isn't familiar with relational databases but understands object-oriented concepts. Plus "addHasAndBelongsToMany()" is even more unwieldy to type than "addManyToMany()".
Lotus Notes
A: 

How about addList or addChildern or addParents or addParentsAndChildren?

Oded
+4  A: 

Perhaps addFriend()? Other options might be addLinked() or addRelated().

Amber
+1 for addRelated()
Josiah
addRelated() sounds great! Thanks.
Lotus Notes
Many to Many Relations are *related* to orgies, addRelated(me)! +1 x)
Alix Axel
A: 

in this example http://pastie.org/938704 wouldn't you just create a method called:

AddUserGame(User someUser, Game someGame)

f00
Interesting idea, however going by the Questions <=> Tags example, a 'QuestionTag' doesn't seem to make much sense as an object in itself. If I was making a page to display questions, the Tags would be children of the Questions, while if I was making a page to display Tags, the Questions would be children of the Tags. I guess it's hard finding a way to describe two things that can both be children of each other!
Lotus Notes
A: 

Tricky! there does not seem to be a generic term that fits "RelateXtoY()" is the best I can come up with.

However for any actual "real" data model there is usually an obvious "verb" which can be used. eg for a many to many relationship between say Country and Airline you could have a method AddRouteTo(CountryId,AirlineId) or TravelledToUsing(CountryId,AirlineId).

James Anderson
A: 

What about this line of thought:

  • connect(X, Y)
  • link(X, Y)
  • bind(X, Y)

Not only is it hard to find names for this kind of relation for Object Oriented systems, it is also hard to model them too! Objects tend to live in hierarchies...

See if you can find a container for such a relationship - check what method names that library uses.

Daren Thomas
A: 

In relational database terms the general case is called an Inclusion Dependency, ie: A is a subset of B, where A and B are projections on some (not necessarily distinct) relations. A "foreign key" is a special case of inclusion dependency where B is a candidate key.

dportas