From abb3f83d94f6a29fb9c5e99583da1344c6d48463 Mon Sep 17 00:00:00 2001 From: Konsta Vesterinen Date: Tue, 6 May 2014 10:59:01 +0300 Subject: [PATCH] Add inheritance example --- sqlalchemy_utils/functions/orm.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/sqlalchemy_utils/functions/orm.py b/sqlalchemy_utils/functions/orm.py index 161b7c2..543113f 100644 --- a/sqlalchemy_utils/functions/orm.py +++ b/sqlalchemy_utils/functions/orm.py @@ -27,6 +27,21 @@ def get_referencing_foreign_keys(mixed): get_foreign_keys(User) # set([ForeignKey('user.id')]) get_foreign_keys(User.__table__) # set([ForeignKey('user.id')]) + + + This function also understands inheritance. This means it returns + all foreign keys that reference any table in the class inheritance tree. + + Let's say you have three classes which use joined table inheritance, + namely TextItem, Article and BlogPost with Article and BlogPost inheriting + TextItem. + + :: + + # This will check all foreign keys that reference either article table + # or textitem table. + get_foreign_key(Article) + """ if isinstance(mixed, sa.Table): tables = [mixed]