Opened 18 years ago
Closed 18 years ago
#3389 closed (fixed)
Allow m2m sets to be assigned by primary key value
Reported by: | Russell Keith-Magee | Owned by: | Adrian Holovaty |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Keywords: | m2m primary key | |
Cc: | Triage Stage: | Design decision needed | |
Has patch: | yes | Needs documentation: | yes |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
At present, m2m relations must be specified using a list of object instances:
john = Author(...) john.save() fred = Author(...) fred.save() Article.authors = [john, fred]
This proposal (and patch) would allow m2m relations be specified using primary key values in place of the object instance:
Article.authors = [john.id, fred.id] # or, if you know the pk values to begin with... Article.authors = [4,7]
The reason for this is twofold:
- For parity with the ability to set m2o related objects by primary key (using Article.author_id = 3)
- To simplify deserialization, removing the need for a query to find related objects while deserializing m2m sets.
Attachments (1)
Change History (2)
by , 18 years ago
Attachment: | m2m_ids.diff added |
---|
comment:1 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
Patch to allow m2m relations to be set by assigning primary key