syrusakbary / Flask-SuperAdmin

The best admin interface framework for Flask. With scaffolding for MongoEngine, Django and SQLAlchemy.
Other
643 stars 134 forks source link

Fix IntegrityError when deleting objects with foreign keys #140

Closed g4b1nagy closed 9 years ago

g4b1nagy commented 9 years ago

According to http://docs.sqlalchemy.org/en/rel_1_0/orm/query.html#sqlalchemy.orm.query.Query.delete, query.delete() "does not offer in-Python cascading of relationships", which essentially means that trying to delete such an object from Flask-SuperAdmin results in an IntegrityError.

I suggest using the session.delete(object) method, as this also takes into account any relationships defined in the SQLAlchemy models.

Please let me know what you think and last but not least, thank you :)

g4b1nagy commented 9 years ago

PS: I am using Flask-SuperAdmin==1.7.1 SQLAlchemy==1.0.0