#24289 closed Bug (fixed)
Is usage of many_to_one and one_to_many terms confusing for relation flags? — at Version 1
Reported by: | Anssi Kääriäinen | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.8alpha1 |
Severity: | Release blocker | Keywords: | |
Cc: | Loic Bistuer, pirosb3, cmawebsite@… | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
EDIT: we haven't mixed the terms up, I did that myself. The docs might need an update though.
It seems we have mixed up the naming of many_to_one and one_to_many. For example these references point out that ForeignKey is many_to_one: http://www-01.ibm.com/support/knowledgecenter/SSEPGG_8.2.0/com.ibm.db2.udb.doc/admin/c0004733.htm, https://docs.djangoproject.com/en/1.7/topics/db/examples/many_to_one/.
But in Django, ForeignKey is one_to_many.
I'm not going to mark this as accepted, as I always get confused with many-to-one and one-to-many. So, please do triage this carefully!
If at all possible I think we should use something that is less easy to get mixed up. I never recall how these terms should be interpreted, and I guess I am not alone here. Some ideas:
- Just is_multivalued flag: Check if field is one to many: "not field.is_multivalued and field.rel.is_multivalued"
- local_multivalued and remote_multivalued flags
My experience from ORM work is that the interesting thing to check is if the relation can have multiple values on the remote side. The local multi-valuedness isn't usually that interesting (although it might be in other contexts).
Change History (1)
comment:1 by , 10 years ago
Description: | modified (diff) |
---|---|
Resolution: | → invalid |
Status: | new → closed |
Summary: | ForeignKey is many_to_one, not one_to_many → Is usage of many_to_one and one_to_many terms confusing for relation flags? |
It seems I did the mixup based on the first sentence of Django's docs (which I guess is technically correct, you use ForeignKey to add the automatically created many-to-one relation), and table 3 of IBM's docs, the first line in there seems to be many-to-one, although the meaning of the header is that the relationships are many-to-one, but the direction the terms appear in the table can actually be one-to-many (nice!).
I'll mark this as invalid. I still do think the terms are confusing.