简体   繁体   中英

Sqlalchemy - getting data from 4 different tables

i am trying to do the following

I have 4 models

user            interest         user_interest       offer
-----------     -------------    ------------       ---------
id (pk)         id (pk)          id (pk)            id (pk)
name            name             user_id (fk)       interest_id (fk)
                                 interest_id (fk)

A user subscribes to multiple interests. I have to get all offers belonging to the interests subscribed by a particular user.

what are the relations I have to set up. I already have the following relations

for user

interests = db.relationship('user_interest', backref='app_user', lazy='dynamic', uselist=True)

also do I need user_interest ?

you need the following relationships

1.a many to many between user and interest tables

2.a one to many between interest and offer

check out how to make these relationships @ http://pythonhosted.org/Flask-SQLAlchemy/models.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM