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:

  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 18 years ago.
Patch to allow m2m relations to be set by assigning primary key

Download all attachments as: .zip

Change History (2)

by Russell Keith-Magee, 18 years ago

Attachment: m2m_ids.diff added

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

comment:1 by Adrian Holovaty, 18 years ago

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