On Mar 27, 2012, at 4:35 AM, Christian Démolis wrote: > Up! > > 2012/3/23 Christian Démolis <[email protected]> > Hi all, > > class A(Base): > __tablename__ = 'a' > IdA = Column('IdA', Integer, primary_key=True) > AllTheB = association_proxy("many_to_many_relation", "relation_b") > > class ManyToManyRelation( > __tablename__ = 'many_to_many_relation' > IdA = Column(Integer, ForeignKey('A.IdA'), primary_key=True) > IdB = Column(Integer, ForeignKey('B.IdB'), primary_key=True) > > relation_a = relationship(A, backref=backref("tarifer_dossier", > cascade="all, delete-orphan")) > relation_b = relationship(B, backref=backref("tarifer_dossier", > cascade="all, delete-orphan")) > > class B(Base): > __tablename__ = 'b' > IdB = Column('IdB ', Integer, primary_key=True) > AllTheA = association_proxy("many_to_many_relation", "relation_a") > > x_a is instance of A > x_b is instance of B > > x_a.AllTheB returns me all the objects B relative to x_a > > When i want to append new element e (instance of A) > x_a.AllTheB.append(e) > > I have an error due to create mechanism of association_prox > > How can i have the same (simple) behaviour of classical many to many > relationship ? > > Thanks in advance > > Chris
Did you try doing exactly what's described at http://docs.sqlalchemy.org/en/latest/orm/extensions/associationproxy.html#simplifying-association-objects ? the example above is not connecting things together correctly; A and B's association proxies would need to refer to "tarifer_dossier", that is, the direction from A->M2M and B->M2M. Each association proxy then has a "creator" which is a lambda that creates ManyToManyRelation in exactly the way it should based on the given input (see http://docs.sqlalchemy.org/en/latest/orm/extensions/associationproxy.html#creation-of-new-values). -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
