开发者

Mapping an arbitrary select to a relation table in sqlachemy

I have a many to many relation table between tables Item and Detail, defined like this:

itemDetail = Table('ItemDetail',Base.metadata, \
            Column('id', Integer, primary_key=True), \
            Column('itemId', Integer, ForeignKey('Item.id')), \
            Column('detailId', Integer, ForeignKey('Detail.id')), \
开发者_JAVA技巧            Column('endDate', Date), \
        )

If I define inside table Item:

details = relation('Detail', secondary=itemDetail) 

it works fine.

But I need something slightly different. The column endDate in ItemDetail table indicates which details are valid. When endDate is null, the details are valid.

So actually, I would need to have in my Item table, something like this:

details = relation('Detail', secondary=validItemDetail)

The problem is defining validItemDetail. I have tried a select statement mapping to an arbitrary class with no success.

Any ideas?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜