I have a User class with a one-to-many relationship to the Item class:
class User(Base):
items=relationship(Item)
def method(self):
for item in self.items
if self.items.itemname=='my item'
#do something
Now I want to get access of some of the items (filtered) of a User in a method inside the User class. Is it more efficient (performance wise) to write a for-loop running over all the items (as it is in the example) or to run a query inside the class? (let's say there are a couple of thousands of items for an average user). I also don't know how I can even run a query inside a class! Is there anything like self.query.filter() way or I should define a session inside the class and run session.query(Items).filter()?