Django

Code

Ticket #3389 (closed: fixed)

Opened 2 years ago

Last modified 2 years ago

Allow m2m sets to be assigned by primary key value

Reported by: russellm Assigned to: adrian
Milestone: Component: Database layer (models, ORM)
Version: SVN Keywords: m2m primary key
Cc: Triage Stage: Design decision needed
Has patch: 1 Needs documentation: 1
Needs tests: 0 Patch needs improvement: 0

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

m2m_ids.diff (3.5 kB) - added by russellm on 01/29/07 06:34:19.
Patch to allow m2m relations to be set by assigning primary key

Change History

01/29/07 06:34:19 changed by russellm

  • attachment m2m_ids.diff added.

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

01/29/07 10:09:47 changed by adrian

  • status changed from new to closed.
  • resolution set to fixed.

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


Add/Change #3389 (Allow m2m sets to be assigned by primary key value)




Change Properties
Action