Relative Content

Tag Archive for pythonsqlalchemy

SQLAlchemy Cascade Delete on Polymorphic M2M relationship

I am building a polymorphic relationship between classes A and B through a Link class.
I want to achieve that when an A object is deleted, the linked B objects are deleted too.
To do that, I defined a relationship between A and Link, with a cascade relationship all, delete, in this way as soon as A is deleted we will try to delete all the links, and then I intercepted the delete on the Link using an event listener before_delete class and I used it to delete also the B object.
A better solution can exist, and most of all I am concerned about the connection object in the event listener that doesn’t seem to be bound to any session.

SQLAlchemy case-sensitive Unicode Column

The title does more or less say everything. I want to create a data model with SQLAlchemy and it should contain fields with values that contain unicode and should be considered case-sensitive.

Self referencing one-to-one SQLAlchemy

Using SQLAlchemy I’m trying to create a one-to-one relationship on the same table. This table represents some physical ethernet ports that can be connected. Here is my code: