WHERE plan_requirements.subscription = 1
Into a SQLAlchemy query. so far from reading the
docs, I have the following:
database.session.query(Person).join(Subscription).filter(Subscription.plan.has() ).all()
With the objective: Show me all people who have at least one plan with the plan_requirements.subscription set to 1 (meaning true).
Do I need to somehow keep chaining my joins?
My SQLAlchemy Models are: (full code is also linked at end)
class Person(database.Model):
__tablename__ = "person"
id = database.Column(database.Integer(), primary_key=True)
uuid = database.Column(database.String(), default=uuid_string)
given_name = database.Column(database.String())
family_name = database.Column(database.String())
subscriptions = relationship("Subscription", back_populates="person")
class Plan(database.Model):
__tablename__ = "plan"
id = database.Column(database.Integer(), primary_key=True)
uuid = database.Column(database.String(), default=uuid_string)
requirements = relationship(
"PlanRequirements", uselist=False, back_populates="plan"
)
class PlanRequirements(database.Model):
__tablename__ = "plan_requirements"
id = database.Column(database.Integer(), primary_key=True)
plan_id = database.Column(database.Integer(), ForeignKey("
plan.id"))
plan = relationship("Plan", back_populates="requirements")
instant_payment = database.Column(database.Boolean(), default=False)
subscription = database.Column(database.Boolean(), default=False)
Full source code of models:
https://github.com/Subscribie/subscribie/blob/master/subscribie/models.py#L40 Much appreciated if someone can point me in the right directly. I'm confident with the SQL quiery, just not how to convert that to the ORM.