在我的models.py in flask app中,我有以下表格:
class PackageBuild(db.Model, helpers.Serializer):
__tablename__ = "package_build"
package_id = db.Column(db.Integer, db.ForeignKey('package.id'))
build_id = db.Column(db.Integer, db.ForeignKey('build.id'))
git_hash = db.Column(db.Text)
version = db.Column(db.Text)
class Build(db.Model):
id = db.Column(db.Integer, primary_key=True)
packages = db.relationship(
'Package',
secondary='package_build',
back_populates='builds'
)
class Package(db.Model):
id = db.Column(db.Integer, primary_key=True)
builds = db.relationship(
'Build',
secondary='package_build',
back_populates='packages'
)
我知道我可以访问相关表的属性:
build.packages[0].id
但是如何访问中间表的属性(例如git_hash)(理想情况下是使用构建实例)?