Skip to content
Advertisement

ORM query many to many to one, Flask sql-alchemy

I have three flask-sqlalchemy-models. Books – unique entries by admin:

Bookscomp – entries by users, related to above:

Company – user, related to above:

Problem: I am trying to get book_name from Book model, through Company + Bookscomp. So a company has many books and each book has reference to general book info.
Tried like this:

Why I cannot get book_name in the above code snippet directly? And how would it be best to achieve this?

Advertisement

Answer

You haven’t defined a relationship between Book and Bookcomp so when you ask for item.book— it’s getting the book = db.Column(db.Integer... value. Maybe tweak your Bookscomp model to be something like:

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement