How do I join three tables with SQLalchemy and keeping all of the columns in one of the tables?

后端 未结 3 1435
情话喂你
情话喂你 2021-02-02 03:01

So, I have three tables:

The class defenitions:

engine = create_engine(\'sqlite://test.db\', echo=False)
SQLSession = sessionmaker(bind=engine)
Base = de         


        
3条回答
  •  你的背包
    2021-02-02 03:41

    Don't query from the user. Query from the Channel.

    user = query(User).filter_by(id=1).one()
    for channel in query(Channel).all():
        print channel.id, channel.title, user in channel.subscriptions.user
    

    That way you get all the channels, not just the ones that are associated with the user in question.

提交回复
热议问题