Finally figured out how to do it : molecule2atom = Table( 'molecule2atom', Base.metadata, Column('molecule_db', Integer), Column('molecule_id', Integer), Column('atom_id', Integer, ForeignKey('atom.id')), ForeignKeyConstraint( ('molecule_db', 'molecule_id'), ('molecule.db', 'molecule.id') ),)
And add the relatiohship to one of the models as usual, for example, in Class Atom add: molecules = relationship("Molecule", secondary=molecule2atom, backref="atoms") On Thursday, March 7, 2013 10:16:24 AM UTC+1, Christian wrote: > > Let's say I have the following model: > > class Molecule(Base): > db = Column(Integer, primary_key=True) > id = Column(Integer, primary_key=True) > data = Column(Integer) > class Atom(Base): > id = Column(Integer, primary_key=True) > weight = Column(Integer) > > And I want to establish a *many-to-many* relationship between Molecule > and Atom, what would be the best way to do it? Notice that the *primary > key* of Molecule is *composite*. > > Thanks > -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.