You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description
I would like to propose the addition of cascade behavior to the generic_relationship feature in SQLAlchemy-Utils. Currently, the absence of cascade options on generic relationships limits their ability to automatically propagate changes to linked tables.
Example
Consider the following example:
classUser(Base):
__tablename__='users'id=sa.Column(sa.Integer, primary_key=True)
classCustomer(Base):
__tablename__='customer'id=sa.Column(sa.Integer, primary_key=True)
classEvent(Base):
__tablename__='event'id=sa.Column(sa.Integer, primary_key=True)
# This is used to discriminate between the linked tables.object_type=sa.Column(sa.Unicode(255))
# This is used to point to the primary key of the linked row.object_id=sa.Column(sa.Integer)
object=generic_relationship(object_type, object_id)
# Add useruser=User()
session.add(user)
session.commit()
# Add eventevent=Event()
event.object=usersession.add(event)
session.commit()
# Delete useruser=session.query(User).first() # only 1 usersessin.delete(user)
session.commit()
# Get event and print object, object_idevent=session.query(Event).first() # This should not have returned any result if cascade-delete was supported in generic_relationshipsprint(event.object)
# Noneprint(event.object_id)
# 1
In this example, when an instance of User is deleted, I expect the associated records in the Event table to be automatically deleted as well, assuming cascade behavior is enabled for the generic_relationship.
Additional Notes:
Enabling cascade behavior on generic_relationship would enhance the usability and consistency of generic relationships in SQLAlchemy-Utils, providing a more intuitive and comprehensive solution for managing relationships between tables.
Thanks in advance
The text was updated successfully, but these errors were encountered:
Description
I would like to propose the addition of cascade behavior to the generic_relationship feature in SQLAlchemy-Utils. Currently, the absence of cascade options on generic relationships limits their ability to automatically propagate changes to linked tables.
Example
Consider the following example:
In this example, when an instance of User is deleted, I expect the associated records in the Event table to be automatically deleted as well, assuming cascade behavior is enabled for the generic_relationship.
Additional Notes:
Enabling cascade behavior on generic_relationship would enhance the usability and consistency of generic relationships in SQLAlchemy-Utils, providing a more intuitive and comprehensive solution for managing relationships between tables.
Thanks in advance
The text was updated successfully, but these errors were encountered: