- attached relationship.patch.gz
Relations vs Relationships
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)
-
Account Deleted -
repo owner 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 ?
-
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.
-
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 therelation()
function would remain for now as a synonym, with at most a long term pending deprecation mark. -
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]
-
Account Deleted Replying to zzzeek:
I propose for now we can rename to
relationship()
but therelation()
function would remain for now as a synonym, with at most a long term pending deprecation mark.That sounds like a good plan.
-
repo owner - changed status to resolved
OK its all in, thanks for the comprehensive patch, in 065fcbd9d2b463920d439c20d99a5a1cd7f216ed. Extensive documentation warnings, since these are our official docs that a lot of 0.5'ers are going to be coming across, are in 50bea2e0e8d4ffa30e4f94ea21748e7ff57d0c0a.
-
repo owner - removed milestone
Removing milestone: 0.6.0 (automated comment)
- Log in to comment
Get rid of relation/relationship confusion