Opened 9 years ago

Closed 9 years ago

#3389 closed (fixed)

Allow m2m sets to be assigned by primary key value

Reported by: russellm Owned by: adrian
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 russellm 9 years ago.
Patch to allow m2m relations to be set by assigning primary key

Download all attachments as: .zip

Change History (2)

Changed 9 years ago by russellm

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

comment:1 Changed 9 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to closed

(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