Set relation to many-to-many relationship Set relation to many-to-many relationship flask flask

Set relation to many-to-many relationship


So if I understand your question correctly, you want to reference the currencies_many table from your orders table. If so, you are correct in having a foreign key relationship with the currencies_many table.

However, down the road you may come into some trouble when you want to query orders from your banks table. I would suggest, although it seems redundant, to create a one-to-many relationship between Order and Bank as well as between Order and Currency.

bank_id = db.Column(db.Integer, db.ForeignKey('bank.id'))currency_id = db.Column(db.Integer, db.ForeignKey('currency.id'))

And then in the Bank class

orders = db.relationship('Order', backref='bank')

This gives you a much cleaner querying interface.

bank_orders = bank.orders

As well as makes your data model cleaner. It would be awkward to have to query orders from an intermediate table that also houses the currency. Just my two cents, but having an easy to understand Data model is better than making awkward relationships to save some redundancy.