I'm trying to create a simple representation for an entity deduplication schema using mysql, and using sqlalchemy for programmatic access.
I'm trying to achieve a specific effect which I think is kind of a self-referential query but i'm not sure:
Essentially I have an 'entities' table (with unique entity_id) and an associated Entity object, and then an entity_groups table which (for simplicity) has a 'group_id' and 'entity_id' columns, so that I 'register' an entity with a group by creating a row for that relation. this table too is associated with an ORM object - EntityGroup.
Question is, how do i get the EntityGroup object reference all entities in the group?
I expect I need to write something like:
mapper(EntityGroup, entity_groups_table, properties={ 'entities': relationship( Entity, .... ? ) },
and i'm alittle fuzzy on the details. Basically I need all the rows in entity_groups that have the same group_id as the row represented by the object. And then I need to materialize all the Entity objects associated those rows' entity_id column. This sounds like something achievable by a more verbose Query() operation in sqlalchemy, but i'm not sure how to combine that with the relationship() construct (if at all - perhaps go manual? )
Any help will be useful, I hope I was clear and to the point