full support for select() to accept mapped entities as from/correlate/etc.

Issue #2245 resolved
Mike Bayer repo owner created an issue

since we don't want to hardcode something like __clause_element__() onto a mapped class, we would need some kind of registration where class_mapper() could be called as part of what expression uses to receive FROM arguments.

Comments (7)

  1. Mike Bayer reporter

    also document this case from #2530:

    from sqlalchemy import *
    from sqlalchemy.orm import *
    from sqlalchemy.ext.declarative import declarative_base
    
    Base = declarative_base()
    
    class SnortEvent(Base):
        __tablename__ = "event"
    
        id = Column(Integer, primary_key=True)
        signature = Column(Integer, ForeignKey("signature.id"))
    
        signatures = relationship("Signature", lazy=False)
    
    class Signature(Base):
        __tablename__ = "signature"
    
        id = Column(Integer, primary_key=True)
    
        sig_count = column_property(
                        select([func.count('*')](func.count('*'))).\
                            where(SnortEvent.signature == id).
                            correlate_except(SnortEvent)
                    )
    
    # workaround
    #Signature.sig_count = column_property(
    #                    select([func.count('*')](func.count('*'))).\
    #                        where(SnortEvent.signature == Signature.id).\
    #                        correlate(Signature.__table__)
    #                )
    
    session = Session()
    
    print session.query(SnortEvent)
    
  2. Mike Bayer reporter

    that is, the docs for column_property() should express correlate_except() in all those cases.

  3. Log in to comment