Changes between Initial Version and Version 1 of Ticket #17253


Ignore:
Timestamp:
Nov 21, 2011, 12:31:53 PM (12 years ago)
Author:
Luke Plant
Comment:

Formatting fixed, please use 'Preview' to check formatting, thanks.

If we don't save M2M objects to the DB immediately when running add(), when do we save them? save() doesn't do that, we would need a 'flush-everything-to-the-database' call, which we don't have. Adding one would require a fundamental change to the way that the ORM works - essentially something like the unit-of-work pattern in SQLAlchemy.

I'm therefore closing WONTFIX.

Note that saving the Group object first doesn't necessarily mean you need to call save() twice - the add() calls do not need to be followed by save(). (I'm guessing you may have reasons why it is this way in your case, but I don't think the situation is forced on you by Django).

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #17253

    • Property Resolutionwontfix
    • Property Status newclosed
  • Ticket #17253 – Description

    initial v1  
    22http://stackoverflow.com/questions/7908349/django-making-relationships-in-memory-without-saving-to-db?answertab=active#tab-top
    33
    4 
     4{{{
     5#!python
    56class Group:
    67   name = models.Chars()
     
    1617class GroupMember:
    1718   group = models.ForeignKey(Group)
    18    member = modesl.ForeignKey(User)
    19 
     19   member = models.ForeignKey(User)
     20}}}
    2021
    2122I have a page to allow people to create Group , and invited existing user to become member.
     
    2728
    2829Example code
     30{{{
     31#!python
    2932
    3033g = Group(name='abc')
     
    3740gm1.save()
    3841gm2.save()
    39 
     42}}}
    4043Since the .add() function save the related object to db immediately , causing error.
    4144
    4245I do not want to save the Group object first , because it will trigger 2 times save()
    43 
    44 
    45 
    46 
    47 
    48 
    49 
    50 
    51 
    52  
Back to Top