I have 3 tables: Account, User and Organization.
Accountconsists ofid,nameandorganization_id.Userconsists ofemailandorganization_id.Organizationconsists ofidandname.
Each Account is registered to an Organization(through organization_id) and each User is registered to an Organization. The challenge is to display all the emails (from User) to the Account corresponding to the name whose organization_id matches the organization_id of User.
Here's my code till now:
class Account(db.Model):
__tablename__ = "account"
id = Column(Integer, primary_key=True)
name = Column(String(50), index=True, unique=True)
organization = Column(Integer,
ForeignKey("organization.id"),nullable=False, index=True)
class User(UserMixin, db.Model, RBACUserMixin):
__tablename__ = "user"
id = db.Column(db.Integer, primary_key=True)
email = db.Column(db.String(255), unique=True)
organization = Column(Integer, ForeignKey("organization.id"),
nullable=False, index=True)
class Organization(db.Model):
__tablename__ = "organization"
id = Column(Integer, primary_key=True)
name = Column(String(512))
users = relationship("User", backref="organizations")
accounts = relationship("Account", backref="organizations")