python - Subscription modelling in Flask SQLAlchemy -
i trying model following scenario in flask sqlalchemy:
there list of subscriptionpacks
available purchase. when particular user
buys subscriptionpack
start instance of subscription
.
the model follows:
a user
can have many subscriptions
(only 1 of active @ time) , each subscription
referencing 1 subscriptionpack
.
how modelled in sqlalchemy?
currently have user.id
, subscriptionpack.id
referenced db.foreignkey
in subscriptions
model. , have subscriptions
referenced db.relationship
in users
table. seems inconsistent , wrong , leading me have hand-code lot of sql statements return right results.
any how right?
for stumble upon this, looking bidirectional sqlalchemy association object pattern.
this allows intermediate table of many-to-many have it's own stored details. in instance above subscription
table needed association object (has it's own class).
Comments
Post a Comment