Opened 11 years ago

Closed 11 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: master
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: UI/UX:


At present, m2m relations must be specified using a list of object instances:

    john = Author(...)
    fred = Author(...)
    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 = [,]
    # or, if you know the pk values to begin with...
    Article.authors = [4,7]

The reason for this is twofold:

  1. For parity with the ability to set m2o related objects by primary key (using Article.author_id = 3)
  2. To simplify deserialization, removing the need for a query to find related objects while deserializing m2m sets.

Attachments (1)

m2m_ids.diff (3.5 KB) - added by Russell Keith-Magee 11 years ago.
Patch to allow m2m relations to be set by assigning primary key

Download all attachments as: .zip

Change History (2)

Changed 11 years ago by Russell Keith-Magee

Attachment: m2m_ids.diff added

Patch to allow m2m relations to be set by assigning primary key

comment:1 Changed 11 years ago by Adrian Holovaty

Resolution: fixed
Status: newclosed

(In [4448]) Fixed #3389 -- Many-to-many sets can now be assigned with primary key values

Note: See TracTickets for help on using tickets.
Back to Top