1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/ihatemoney_ynh.git synced 2024-09-03 19:26:15 +02:00

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
This commit is contained in:
Alexis Metaireau 2011-10-18 17:45:24 +02:00
parent c3b3e2f770
commit 6e3834048b

View file

@ -99,10 +99,9 @@ class Person(db.Model):
activated = db.Column(db.Boolean, default=True) activated = db.Column(db.Boolean, default=True)
def has_bills(self): def has_bills(self):
bills_as_ower_number = db.session.query(Bill).join(billowers, Person)\ """return if the user do have bills or not"""
.filter("Bill.id == billowers.bill_id")\ bills_as_ower_number = db.session.query(billowers)\
.filter("Person.id == billowers.person_id")\ .filter(billowers.columns.get("bill_id") == self.id)\
.filter(Person.id == self.id)\
.count() .count()
return bills_as_ower_number != 0 or len(self.bills) != 0 return bills_as_ower_number != 0 or len(self.bills) != 0