Hello,

I need your help with one query, I want to get Category items that some 
Product's of some Brand have.

I try DBSession.query(Category).filter(Category.overviews.any(Brand.slug == 
brand_slug)).order_by(Category.name)
But it doesn't work as expected because there is no relation between Brand 
and other tables


class Brand(Base):
    __tablename__ = 'brand'

    id = Column(Integer, primary_key=True)
    name = Column(UnicodeText, nullable=False)
    slug = Column(UnicodeText, nullable=False, unique=True)


class Category(Base):
    __tablename__ = 'category'

    id = Column(Integer, primary_key=True)
    name = Column(UnicodeText, nullable=False)


class Product(Base):
    __tablename__ = 'product'

    id = Column(Integer, primary_key=True)
    brand_id = Column(Integer, ForeignKey('brand.id'), nullable=False)

    name = Column(UnicodeText, nullable=False)

    brand = relationship('Brand', backref='products')
    categories = relationship('Category', backref='products', 
secondary=product_category)   # many-to-many relationship



-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to