From 6e3834048b2b23a07afd5d2354b92131c2c175f9 Mon Sep 17 00:00:00 2001 From: Alexis Metaireau Date: Tue, 18 Oct 2011 17:45:24 +0200 Subject: Use the relation table for "has_bills". This fixes a bug related to the way we made joins to query q postgresql db. I found that we didn't needed at all any join, so a simple lookup in the m2m relation table allows to speed up things. Fix #44 --- budget/models.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/budget/models.py b/budget/models.py index a73f8e9..e5d5ea9 100644 --- a/budget/models.py +++ b/budget/models.py @@ -99,10 +99,9 @@ class Person(db.Model): activated = db.Column(db.Boolean, default=True) def has_bills(self): - bills_as_ower_number = db.session.query(Bill).join(billowers, Person)\ - .filter("Bill.id == billowers.bill_id")\ - .filter("Person.id == billowers.person_id")\ - .filter(Person.id == self.id)\ + """return if the user do have bills or not""" + bills_as_ower_number = db.session.query(billowers)\ + .filter(billowers.columns.get("bill_id") == self.id)\ .count() return bills_as_ower_number != 0 or len(self.bills) != 0 -- cgit v1.1