Many-to-Many with three tables relating with each other (SqlAlchemy)
I've three tables User, Device and Role. I have created a many-to-many relation b/w User and Device like this; #Many-to-Many relation between User and Devices userDevices = db.Table("user_devices", db.Column("id", db.Integer, primary_key=True), db.Column("user_id", db.Integer, db.ForeignKey("user.id")), db.Column("device_id", db.Integer, db.ForeignKey("device.id")))) class User(db.Model): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(60), index=True, unique=True) devices = db.relationship("Device", secondary=userDevices, backref=db.backref(