Skip to content

Instantly share code, notes, and snippets.

@deontologician
Last active December 17, 2015 22:59
Show Gist options
  • Save deontologician/5686295 to your computer and use it in GitHub Desktop.
Save deontologician/5686295 to your computer and use it in GitHub Desktop.
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import *
Base = declarative_base()
class Access(Base):
__tablename__ = 'accesses'
access_id = Column(Integer, primary_key=True)
user_id = Column(Integer)
building_id = Column(Integer, ForeignKey('building.building_id'))
building = relationship('Building', backref='accesses')
class Building(Base):
__tablename__ = 'building'
building_id = Column(Integer, primary_key=True)
destroyed = Column(Boolean)
engine = create_engine('sqlite:///:memory:')
Session = sessionmaker(bind=engine)
session = Session()
Base.metadata.create_all(engine)
user_id = 12
session.query(Access).filter(Access.user_id == user_id, Access.building.destroyed == False).all()
# Raises:
# AttributeError: Neither 'InstrumentedAttribute' object nor 'Comparator' object associated with Access.building has an attribute 'destroyed'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment