title: Mapping an arbitrary select to a relation table in sqlachemy
body: <p>I have a many to many relation table between tables Item and Detail, defined like this:</p>
  
  <pre><code>itemDetail = Table('ItemDetail',Base.metadata, \
              Column('id', Integer, primary_key=True), \
              Column('itemId', Integer, ForeignKey('Item.id')), \
              Column('detailId', Integer, ForeignKey('Detail.id')), \
              Column('endDate', Date), \
          )
  </code></pre>
  
  <p>If I define inside table Item:</p>
  
  <pre><code>details = relation('Detail', secondary=itemDetail) 
  </code></pre>
  
  <p>it works fine.</p>
  
  <p>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. </p>
  
  <p>So actually, I would need to have in my Item table, something like this:</p>
  
  <pre><code>details = relation('Detail', secondary=validItemDetail)
  </code></pre>
  
  <p>The problem is defining validItemDetail. I have tried a select statement mapping to an arbitrary class with no success.  </p>
  
  <p>Any ideas?</p>