我无法从外部表获取属性:
教堂表:
class ChurchModel(db.Model):
__tablename__ = 'churches'
church_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
name = db.Column(db.String(80))
部长表:
class MinisterModel(db.Model):
__tablename__ = 'ministers'
minister_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
name = db.Column(db.String(80))
home_assembly_id = db.Column(db.Integer)
church = db.relationship('ChurchModel') # join
church_id = db.Column(db.Integer, db.ForeignKey('churches.church_id'))
当我尝试这样做时:
church_name = ChurchModel.query.filter_by(church_id=self.church_id).first().name
我收到此错误:
church_name = ChurchModel.query.filter_by(church_id=self.church_id).first().name
AttributeError: 'NoneType' object has no attribute 'name'
答案 0 :(得分:-1)
尝试一下
church_name = ChurchModel.query.filter(ChurchModel.church_id=self.church_id).first().name
答案 1 :(得分:-2)
尝试以下
let citiesRef = db.collection("clubs")
.whereField( "owners", arrayContains: 2)
.getDocuments()