Hello,
I am stuck here with a query, it't not too complicated I think, but I dont
get it...
I have three Class/table mappings:
Shots, Assets, which belong to a Shot (1:n) and AssetCategories, which are
owned by Assets (n:1)
The objective is:
For a given shot instance get all distinct AssetCategories.
To be sure I articulate myself correct: I want all asset categories for
one shot so that there are not doublets within the categories result.
I thought I could achieve this with distinct. How do I use joins with
distinct, or is this the wrong approach?
Thanks for having a look at this!
Here are the definitions:
from sqlalchemy import create_engine, Column,Integer, ForeignKey
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker,relation, backref
engine = create_engine("sqlite:///:memory:",echo=True)
Base=declarative_base()
class Asset(Base):
__tablename__="Asset"
id=Column(Integer,primary_key=True)
shot_id = Column(Integer, ForeignKey('Shot.id'))
shot=relation(Shot,backref=backref('assets',order_by=id))
category_id = Column(Integer, ForeignKey('AssetCategory.id'))
category=relation(AssetCategory,backref=backref('assets',order_by=id))
class AssetCategory(Base):
__tablename__="AssetCategory"
id=Column(Integer,primary_key=True)
class Shot(Base):
__tablename__="Shot"
id=Column(Integer, primary_key=True)
Base.metadata.create_all(engine)
Session=sessionmaker(bind=engine)
session = Session()
Regards
Sebastian
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.