Hi, I'm currently learning the how to set up a basic Entity System with sqlalchemy. The entity system requirements are described within this link: http://t-machine.org/index.php/2009/10/26/entity-systems-are-the-future-of-mmos-part-5/
Basically, an Entity that lives with the world is defined by the Components that are attached to it. The nature of the Entity is described by the combinations of Components attached to the entity. An Entity can change it's nature by removing or adding a Component to the entity. Every Component is backed by a table with it's associated data. The Components are indexed within the 'components_dir' table. As you can see by the schema below, each Entity can be mapped differently to different Components based of EntityComponentMap and this can change anytime with the state of the object. In order to grab an Entity's component data, I'll retrieve the Component's tablename via ComponentsDirectory. I'll then manually retrieve the data row with component_id from it's individual component table. I'm sorry, I'm kinda really new to sqlalchemy or database based programming, but is there anyway for sqlalchemy to dynamically directly map or join the entity to the individual final component data tables? I've setup the following tables: class Entity(Base): __tablename__ = 'entities' id = Column(Integer, primary_key=True) name = Column(String) class ComponentsDirectory(Base): __tablename__ = 'components_dir' id = Column(Integer, primary_key=True) name = Column(String, nullable=False, unique=True) cls_name = Column(String, nullable=False, unique=True) table_name = Column(String, nullable=False, unique=True) class EntityComponentMap(Base): __tablename__ = 'entity_component_map' id = Column(Integer, primary_key=True) entity_id = Column(Integer, ForeignKey('entities.id')) component_type_id = Column(Integer, ForeignKey(components_dir.id)) component_id = Column(Integer) entity = relationship('Entity', backref=backref('component_types_assoc')) component_type = relationship('ComponentsDirectory', backref=backref('entities_assoc')) class ComponentA(Base): __tablename__ = 'component_b' id = Column(Integer, primary_key=True) data_field1 = Column(Integer) class ComponentB(Base): __tablename__ = 'component_b' id = Column(Integer, primary_key=True) data_field1 = Column(Integer) data_field2 = Column(String) class ComponentC(Base): __tablename__ = 'component_c' id = Column(Integer, primary_key=True) data_field1 = Column(Integer) data_field2 = Column(String) data_field3 = Column(Boolean) -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/groups/opt_out.