Changes between Version 3 and Version 4 of Ticket #26366
- Timestamp:
- Mar 17, 2016, 7:46:54 AM (9 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #26366
- Property Resolution → wontfix
- Property Status new → closed
- Property Summary models.Model.save() method improvement. → Implicitly save related models as needed instead of raising "unsaved related objects error" on Model.save()
-
Ticket #26366 – Description
v3 v4 7 7 foo = models.ForeignKey(Foo) 8 8 9 foo = Foo()10 bar = Bar(foo=foo)9 >>> foo = Foo() 10 >>> bar = Bar(foo=foo) 11 11 12 12 ------------------------- 13 bar.save() <- Fail 13 >>> bar.save() 14 ... 15 ValueError: save() prohibited to prevent data loss due to unsaved related object 'foo'. 14 16 15 17 ------------------------- 16 foo.save() 17 bar.save() <- Fail 18 >>> foo.save() 19 >>> bar.save() 20 IntegrityError: NOT NULL constraint failed: t26366_bar.foo_id 18 21 19 22 ------------------------- 20 foo.save() 21 bar.foo = bar.foo 22 bar.save() <- Success! 23 >>> foo.save() 24 >>> bar.foo = bar.foo 25 >>> bar.save() 26 (no errors) 23 27 24 28 }}} … … 26 30 This is very odd behavior. 27 31 28 And, when implementing bar.save() without foo.save(), I wish Django implemented foo.save()implicitly.29 Like QuerySet.delete(), ON DELETE CASCADE emulation.32 And, when implementing `bar.save()` without `foo.save()`, I wish Django implemented `foo.save()` implicitly. 33 Like `QuerySet.delete()`, ON DELETE CASCADE emulation.