Skip to content

Instantly share code, notes, and snippets.

@inklesspen
Created April 17, 2009 13:50
Show Gist options
  • Save inklesspen/97035 to your computer and use it in GitHub Desktop.
Save inklesspen/97035 to your computer and use it in GitHub Desktop.
class Table(Base):
__tablename__ = 'tables'
id = Column(Integer, primary_key=True)
user_tables = relation("UserTable", backref='table', cascade="all, delete, delete-orphan")
users = association_proxy("user_tables", "user")
class UserTable(Base):
__tablename__ = "user_tables"
user_id = Column(Integer, ForeignKey("users.id"), primary_key=True)
table_id = Column(Integer, ForeignKey("tables.id"), primary_key=True)
uuid = Column(String(32), unique=True, nullable=False, default=generate_uuid, index=True)
class User(Base):
__tablename__ = "users"
id = Column(Integer, primary_key=True)
username = Column(String(32), unique=True, nullable=False)
user_tables = relation("UserTable", backref='user', cascade="all, delete, delete-orphan")
tables = association_proxy("user_tables", "table")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment