开发者

Mapping an arbitrary select to a relation table in sqlachemy

开发者 https://www.devze.com 2023-03-03 17:54 出处:网络
I have a many to many relation table between tables Item and Detail, defined like this: itemDetail = Table(\'ItemDetail\',Base.metadata, \\

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

精彩评论

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