mark at microenh.com
Sun Aug 22 03:07:29 CEST 2010
I've run into an issue with SQLAlchemy dealing with a parent child relationship. I'm using Python 2.6 and SQLAlchemy 0.5.8 with a SQLite in memory database for testing.
According to the SQLAlchemy docs, SA can use lists or sets as the container for child objects
If I use a list as the container for the child objects, things seem to work properly.
If I use a set as the container for the child objects and add a new child object and commit the session, the data is updated to the database correctly. If I delete a child object, the corresponding record in the database isn't getting deleted.
To get the set working (this far), I added __hash__, __cmp__ and __eq__ methods to the child class so that instances with the same data compare equally and hash to the same value so that only one instance with the same data can be added.
More information about the CentralOH