diff options
| author | mike bayer <mike_mp@zzzcomputing.com> | 2018-07-12 17:41:25 -0400 |
|---|---|---|
| committer | Gerrit Code Review <gerrit@ci.zzzcomputing.com> | 2018-07-12 17:41:25 -0400 |
| commit | 3cad4e0371c99b79fbf5ce4955cdd6489325fd61 (patch) | |
| tree | 985b786e0902dac19856fe33e651570a7fcdd943 /doc | |
| parent | 5e6cfc306273bb6f1a873e9ca580e0effec57bc3 (diff) | |
| parent | 9f09b6ef1807574a1fa9d155d5a80dba455285fd (diff) | |
| download | sqlalchemy-3cad4e0371c99b79fbf5ce4955cdd6489325fd61.tar.gz | |
Merge "Don't null FK for collection-removed item with passive_deletes='all'"
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/build/changelog/migration_13.rst | 41 | ||||
| -rw-r--r-- | doc/build/changelog/unreleased_13/3844.rst | 13 |
2 files changed, 54 insertions, 0 deletions
diff --git a/doc/build/changelog/migration_13.rst b/doc/build/changelog/migration_13.rst index 9f2b71818..5740728a2 100644 --- a/doc/build/changelog/migration_13.rst +++ b/doc/build/changelog/migration_13.rst @@ -87,6 +87,47 @@ and can't easily be generalized for more complex queries. :ticket:`4246` +.. _change_3844 + +passive_deletes='all' will leave FK unchanged for object removed from collection +-------------------------------------------------------------------------------- + +The :paramref:`.relationship.passive_deletes` option accepts the value +``"all"`` to indicate that no foreign key attributes should be modified when +the object is flushed, even if the relationship's collection / reference has +been removed. Previously, this did not take place for one-to-many, or +one-to-one relationships, in the following situation:: + + class User(Base): + __tablename__ = 'users' + + id = Column(Integer, primary_key=True) + addresses = relationship( + "Address", + passive_deletes="all") + + class Address(Base): + __tablename__ = 'addresses' + id = Column(Integer, primary_key=True) + email = Column(String) + + user_id = Column(Integer, ForeignKey('users.id')) + user = relationship("User") + + u1 = session.query(User).first() + address = u1.addresses[0] + u1.addresses.remove(address) + session.commit() + + # would fail and be set to None + assert address.user_id == u1.id + +The fix now includes that ``address.user_id`` is left unchanged as per +``passive_deletes="all"``. This kind of thing is useful for building custom +"version table" schemes and such where rows are archived instead of deleted. + +:ticket:`3844` + New Features and Improvements - Core ==================================== diff --git a/doc/build/changelog/unreleased_13/3844.rst b/doc/build/changelog/unreleased_13/3844.rst new file mode 100644 index 000000000..8c65c47cd --- /dev/null +++ b/doc/build/changelog/unreleased_13/3844.rst @@ -0,0 +1,13 @@ +.. change:: + :tags: bug, orm + :tickets: 3844 + + Fixed issue regarding passive_deletes="all", where the foreign key + attribute of an object is maintained with its value even after the object + is removed from its parent collection. Previously, the unit of work would + set this to NULL even though passive_deletes indicated it should not be + modified. + + .. seealso:: + + :ref:`change_3844` |
