带有三个外键的 sqlalchemy 关联表

use*_*920 5 python sqlalchemy

我正在学习 sqlalchemy 中的关联对象以及一般的表关系。我有一个应用程序,用户可以在其中将标签应用于文章。为了捕捉这一点,我创建了一个包含三个外键的关联表。我开始明白你永远不会这样做,因为一个关联只能有一个左和一个右(即关联两个表)。不过,我觉得这个主意还是不错的。我会使用这个关联对象来查找用户用给定标签标记的文章。我不明白什么?

class UsersAppliedTags(alchemyDB.Model):
    '''
        a association object to handle the tags which a user applies to other people's entries
    '''
    __tablename__ = 'users_applied_tags'
    id = alchemyDB.Column(alchemyDB.Integer, primary_key = True)
    tag_id = alchemyDB.Column(alchemyDB.Integer, alchemyDB.ForeignKey('tagTable.id'))
    entry_id = alchemyDB.Column(alchemyDB.Integer, alchemyDB.ForeignKey('entries.id'))
    user_id = alchemyDB.Column(alchemyDB.Integer, alchemyDB.ForeignKey('users.id'))
Run Code Online (Sandbox Code Playgroud)