On Sep 23, 2006, at 11:00 PM, Rúben Leote Mendes wrote:
im skeptical of this mapping, particularly with regards to write operations, since the "rel_table" is semantically ambiguous. is it an association table, or is it the table that stores "Relationship" entities ? by using it for both at the same time the save process may very well produce conflicting operations. the "secondary" table is assumed to usually be a table that only contains foriegn keys to the two related tables. it seems here that it would be useful if the mapping of Information to itself could have some kind of "read-only" flag, since its not really a complete mapping of the "rel_table". it might be the case that during a flush operation, things just work out anyway, so maybe its good enough in that regard. you could also try the "relations" relation mapping using just a single "primaryjoin" across the two tables. *or*, not even have it and just use a property accessor, this is the cleaner way to do it: def _relations(self): foreach x in self.relation_direct: foreach y in x.relation_inverse: yield y def _add_relation(self, info): info.relation_inverse.append(self) self.relation_direct.append(info) relations = property(_relations, _add_relation)
normally when you want an assocaition with extra data you use the Assocaition Object pattern, which has an example at http://www.sqlalchemy.org/docs/datamapping.myt#datamapping_association. but since you already have the Relation objects associated with your Information, the approach I outlined above is the most direct.
info2 = info_table.alias('info2') session.query(Information).select( info_table.select( and_(info2.c.pk==17,rel_table.c.rel_data=='somedata'), from_obj=[info_table.join(rel_table, info_table.c.pk==rel_table.c.info_fk_one).join(info2, info2.c.pk==rel_table.c.info_fk_two)] ) ) |
------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________ Sqlalchemy-users mailing list Sqlalchemy-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users