Hi all, I'm having some trouble with using a schema with a many-to-many declarative mapping. The error i'm getting is as follows:
" sqlalchemy.exc.InvalidRequestError: One or more mappers failed to compile. Exception was probably suppressed within a hasattr() call. Message was: One or more mappers failed to compile. Exception was probably suppressed within a hasattr() call. Message was: When compiling mapper Mapper|Entity|entity, expression 'Entity.id == entityConnections.c.masterId' failed to locate a name ("name 'entityConnections' is not defined"). If this is a class name, consider adding this relationship() to the <class '__main__.Entity'> class after both dependent classes have been defined. " Here is a bit of code that will fail. Please excuse the word wrapping: " Base = declarative_base( bind = engine ) entityConnection = Table( 'entityConnections', Base.metadata, Column( 'masterId', Integer, ForeignKey( 'relationalSchema.entity.id' ), primary_key = True ), Column( 'slaveId', Integer, ForeignKey( 'relationalSchema.entity.id' ), primary_key = True ), schema = 'relationalSchema' ) class Entity( Base ): __tablename__ = 'entity' __table_args__ = { 'schema':'relationalSchema' } id = Column( Integer, primary_key = True ) entityType = Column(String) connections = relationship( 'Entity', secondary = entityConnection, primaryjoin = "Entity.id == entityConnections.c.masterId", secondaryjoin = "Entity.id == entityConnections.c.slaveId",backref = 'entity' ) def __init__(self, entityType ): self.entityType = entityType def __repr__(self): return "<Entity('%s')>" % ( self.entityType ) from sqlalchemy.orm import sessionmaker Session = sessionmaker(bind=engine) session = Session() session.add( Entity( 'test' ) ) " If I remove the references to the schema the code runs fine. Adding the schema to the primaryjoin and secondaryjoin just changes the error so it must be something else. Any ideas what I'm doing wrong here? I'm a rank newbie with sqlalchemy so it's probably a pretty easy thing to fix! -- 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.