Opened 8 years ago

Last modified 8 years ago

#26366 closed New feature

models.Model.save() method improvement. — at Version 2

Reported by: aki33524 Owned by: nobody
Component: Database layer (models, ORM) Version: 1.9
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by aki33524)

class Foo(models.Model):
  pass

class Bar(models.Model):
  foo = models.ForeignKey(Foo)

foo = Foo()
bar = Bar(foo=foo)

-------------------------
bar.save() <- Fail

-------------------------
foo.save()
bar.save() <- Fail

-------------------------
foo.save()
bar.foo = bar.foo
bar.save() <- Success!

This is very odd behavior.

And, when implementing foo.save() without foo.save(), I wish Django implemented foo.save() implicitly.
Like QuerySet.delete(), ON DELETE CASCADE emulation.

Change History (2)

comment:1 by aki33524, 8 years ago

Component: UncategorizedDatabase layer (models, ORM)

comment:2 by aki33524, 8 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top