diff options
| author | Alexis Metaireau <alexis@notmyidea.org> | 2011-10-18 17:45:24 +0200 |
|---|---|---|
| committer | Alexis Metaireau <alexis@notmyidea.org> | 2011-10-18 17:48:23 +0200 |
| commit | 6e3834048b2b23a07afd5d2354b92131c2c175f9 (patch) | |
| tree | 96fcdd6fbf0882250dab2dc12e1544ea13933cb9 /budget | |
| parent | c3b3e2f770173b4d2ac52497aeca702537e0e755 (diff) | |
| download | ihatemoney-mirror-6e3834048b2b23a07afd5d2354b92131c2c175f9.zip ihatemoney-mirror-6e3834048b2b23a07afd5d2354b92131c2c175f9.tar.gz ihatemoney-mirror-6e3834048b2b23a07afd5d2354b92131c2c175f9.tar.bz2 | |
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
Diffstat (limited to 'budget')
| -rw-r--r-- | budget/models.py | 7 |
1 files 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 |
