class OrgsAndUsers(db.Model): __tablename__ = "associations" user_id = db.Column(db.Integer, db.ForeignKey("user.id", ondelete="CASCADE"), primary_key=True) org_id = db.Column(db.Integer, db.ForeignKey("organization.id", ondelete="CASCADE"), primary_key=True) user2 = db.relationship("User", back_populates="orgs") org = db.relationship("Organization", back_populates="users2")
class EventsAndUsers(db.Model): __tablename__ = "following" user_id = db.Column(db.Integer, db.ForeignKey("user.id", ondelete="CASCADE"), primary_key=True) event_id = db.Column(db.Integer, db.ForeignKey("event.id", ondelete="CASCADE"), primary_key=True) user1 = db.relationship("User", back_populates="events") event = db.relationship("Event", back_populates="users1")
class Organization(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(128), unique=True, nullable=False) event = db.relationship("Event", back_populates="org") #users1 = db.relationship('User', secondary=associations, lazy='subquery', #backref=db.backref('related_orgs', lazy=True)) #users2 = db.relationship('User',secondary=associations)#back_populates='related_orgs') users2 = db.relationship("OrgsAndUsers", back_populates="org", cascade="all,delete-orphan")
class Event(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(128), nullable=False) time = db.Column(db.String(128), nullable=False) description = db.Column(db.String(255), nullable=False) location = db.Column(db.String(128)) organization = db.Column( db.Integer, db.ForeignKey("organization.id", ondelete="CASCADE")) org = db.relationship("Organization", back_populates="event") #users1 = db.relationship("User",secondary=following)#,back_populates='followed_events') users1 = db.relationship("EventsAndUsers", back_populates="event", cascade="all,delete-orphan")
class User(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(128), nullable=False) email = db.Column(db.String(128), unique=True, nullable=False) pwdhash = db.Column(db.String(128), nullable=False) location = db.Column(db.String(128)) notifications = db.Column(db.Integer, CheckConstraint('notifications IN (0, 1)'), nullable=False) #followed_events = db.relationship('Event', secondary=following)#,back_populates='users1') """ related_orgs = db.relationship('Organization', secondary=associations, lazy='subquery', backref=db.backref('users2', lazy=True)) """ #related_orgs = db.relationship("Organization",secondary=associations)#,back_populates='users2') events = db.relationship("EventsAndUsers", back_populates="user1", cascade="all,delete-orphan") #delete-orphan orgs = db.relationship("OrgsAndUsers", back_populates="user2", cascade="all,delete-orphan")