So with SQLAlchemy i want to create 3 tables
Obj
obj_id | obj_type
User
user_id | obj_id | name | mail
Society
society_id | obj_id | name
so lets say i push 3 elements and i want to have something like this :
Obj
obj_id | obj_type
1 | society
2 | user
3 | society
User
user_id | obj_id | name | mail
1 | 2 | John | [email protected]
Society
society_id | obj_id | name
1 | 1 | Google
2 | 3 | Facebook
how do i construct my code and add / commit so i link my tables?
class Obj(Base):
__tablename__ = 'objects'
obj_id = Column(Integer, primary_key=True)
obj_type = Column(String(30))
class User(Base):
__tablename__ = 'users'
user_id = Column(Integer, primary_key=True)
obj_id = Column(Integer, ForeignKey('objects.obj_id'))
name = Column(String(100), default=None)
mail = Column(String(200), default=None)
objects = relationship("Obj", back_populates="users")
class Society(Base):
__tablename__ = 'society'
society_id = Column(Integer, primary_key=True)
obj_id = Column(Integer, ForeignKey("objects.obj_id"))
name = Column(String(100), default=None)
objects = relationship("Obj", back_populates="society")
people = relationship("People", back_populates="society")