Relations vs Relationships

Issue #1740 resolved
Former user created an issue

The code and docs use "relation" and "relationship" interchangeably as though they were the same thing, but in relational databases, a relation has a specific meaning (and is more commonly referred to as a table). This makes learning SQLAlchemy confusing for people familiar with the relational model terminology.

This patch renames relation to relationship in the code and docs to avoid this confusion. Any chance something like this could be applied in a future major version?

Comments (8)

  1. Mike Bayer repo owner
    • changed component to orm
    • changed milestone to blue sky

    I agree the name choice of relation() is unfortunate and I have said as much at most of the talks I've done at Pycon and similar. However it's been that way since the beginning and seems to be a word that people usually understand immediately in the non-"relational" sense. Changing the name would cause a lot of suffering.

    I actually searched pretty hard for some document that explicitly stated the difference between "relationship" and "relation" and couldn't find, do you have a link ?

  2. Former user Account Deleted

    You're right that many people confuse them because in English there is little difference between a relation and a relationship, but in the domain of relational databases, I think it's somewhat important to use the terminology correctly, or at least avoid using it incorrectly. (Especially to be able to recommend the tool in a learning environment.)

    I know this would cause a lot of suffering to change, so would it be possible to make relationship() an alias to the current relation() function, as well as update the docs?

    As far as a document explaining the difference, the relational database and relational model articles on Wikipedia use the 'relation' term correctly. For example, "a relation is defined as a set of tuples that have the same attributes" and "a table is an accepted visual representation of a relation; a tuple is similar to the concept of row". Also, the discussion page shows that it used to include "'Relation' is a mathematical term for 'table', and thus 'relational' roughly means 'based on tables'. It does not refer to the links or 'keys' between tables, contrary to popular belief." Also this article may explain it better: "The relational model consists of a collection of tables (more properly, relations) with relationships between tables being provided by columns. The relational model is based on the mathematics of set theory. Contrary to popular belief, the relational model is not named after 'relationships', but after the relations of set theory. A relation is basically a set with no duplicate values."

    Pretty much any definition of "relational database" I could find clearly explains that it refers to a database of relations (i.e. tables).

    Hope that helps.

  3. Mike Bayer repo owner
    • changed milestone to 0.6.0

    right, I was looking for confirmation that "relationship" is in fact a different term.

    I propose for now we can rename to relationship() but the relation() function would remain for now as a synonym, with at most a long term pending deprecation mark.

  4. Former user Account Deleted

    Ah sorry, I'm not 100% sure that it's the perfect term, but it's generally used when people refer to one-to-many relationships or many-to-many relationships or entity-relationship model. I've also heard it called a reference or association.

    Out of curiosity, I also just checked what names some other ORMs used:

    Django: ForeignKey, ManyToManyField, OneToOneField[BR] SQLObject: ForeignKey, RelatedJoin, MultipleJoin, SingleJoin[BR] Storm: Reference, ReferenceSet[BR]

  5. Former user Account Deleted

    Replying to zzzeek:

    I propose for now we can rename to relationship() but the relation() function would remain for now as a synonym, with at most a long term pending deprecation mark.

    That sounds like a good plan.

  6. Log in to comment