Reputation: 2063
I'm using Python 2.7+flask-sqlalchemy. I have the following models/table defined:
class Detail(db.Model):
__tablename__ = 'details'
id = db.Column(db.Integer, primary_key=True)
....
class Usage(db.Model):
__tablename__ = 'details'
id = db.Column(db.Integer, primary_key=True)
details = db.relationship('Detail', secondary=details_usages, backref=db.backref('usages', lazy='dynamic'))
....
details_usages = db.Table('details_usages',
db.Column('detail_id', db.Integer, db.ForeignKey('details.id')),
db.Column('usage_id', db.Integer, db.ForeignKey('usages.id')),
db.Column('is_required', db.Integer)
)
I have the following query:
models.Detail.query.join(details_usages).add_columns('details_usages.is_required').all()
I'm getting the following error:
NoSuchColumnError: "Could not locate column in row for column 'details_usages.is_required'"
What am I doing wrong?
Upvotes: 1
Views: 453
Reputation: 2063
I found the solution. The correct way of querying should be:
models.Detail.query.join(details_usages).add_columns(details_usages.c.is_required).all()
Upvotes: 3