Last active
December 17, 2015 22:59
-
-
Save deontologician/5686295 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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