From 12b53d873b26d248678faa8b1e4caa7749a3c769 Mon Sep 17 00:00:00 2001 From: Konsta Vesterinen Date: Thu, 8 Aug 2013 15:13:45 +0300 Subject: [PATCH] More examples added for batch_fetch --- sqlalchemy_utils/functions.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/sqlalchemy_utils/functions.py b/sqlalchemy_utils/functions.py index e6a5127..bb19f03 100644 --- a/sqlalchemy_utils/functions.py +++ b/sqlalchemy_utils/functions.py @@ -411,6 +411,27 @@ def batch_fetch(entities, *attr_paths): users = session.query(User).limit(20).all() batch_fetch(users, User.phonenumbers) + + + Function also accepts strings as attribute names: :: + + + users = session.query(User).limit(20).all() + + batch_fetch(users, 'phonenumbers') + + + Multiple attributes may be provided: :: + + + clubs = session.query(Club).limit(20).all() + + batch_fetch( + clubs, + 'teams', + 'teams.players', + 'teams.players.friends' + ) """ if entities: