I have 3 tables, Model
, Parameter
and Value
where parameters point to model and values to parameters.
What I want to do is to filter
the parameters of some model by conditions on the parameter and the values and return only those parameters and values that match the criteria.
What I tried is something like:
model.params.join(Value).filter(Param.name.in_(<whatever>), Value.type == xx, Value.count < yy)
This returns the expected Param
objects, however it returns all the Value
s of those Param
, including ones with, for example, count > yy
.
What do I need to change in the query to get the result I want?
EDIT
This is how the relevant part of the tables looks like:
class Model(Base):
__tablename__ = 'models'
params = relationship('Param', cascade='all, delete-orphan', lazy='dynamic', back_populates='model')
class Param(Base):
__tablename__ = 'params'
model = relationship('Model', back_populates='params')
values = relationship('Value', cascade='all, delete-orphan', order_by='asc(Value.count)', back_populates='param')
class Value(Base):
__tablename__ = 'values'
name = Column(String(128))
count = Column(Integer)
param = relationship('Param', back_populates='values')