Запрос при M:N SQLAlchemy
Есть две таблицы:
class Attribute(Base):
__tablename__ = "attribute"
id = Column(BIGINT, primary_key=True, index=True)
caption = Column(VARCHAR(128), nullable=False)
attribute_values = relationship('AttributeValue', secondary='attributes_to_values')
class AttributeValue(Base):
__tablename__ = "attribute_value"
id = Column(BIGINT, primary_key=True, index=True)
varchar_value = Column(VARCHAR(), nullable=False)
attributes = relationship('Attribute', secondary='attributes_to_values')
Они связаны между собой M:N. Ассоциативная таблица:
class AttributeToValue(Base):
__tablename__ = 'attributes_to_values'
attribute_id = Column(BIGINT, ForeignKey('attribute.id'), primary_key=True)
value_id = Column(BIGINT, ForeignKey('attribute_value.id'), primary_key=True)
Как мне через запрос session.query() получить все объекты AttributeValue, имеющие связь с определенным объектом Attribute?