Thanks a lot

It works well

Long life to SqlAlchemy and Python

2012/3/28 Michael Bayer <[email protected]>

> "creator" is in terms of creating a new association:
>
> Dossier.LesTar = association_proxy("tarifer_dossier", "article_tarife",
> creator=lambda art:DossierTarife(article_tarife=art))
> ArticleTarife.LesTar = association_proxy("tarifer_dossier", "dossier",
> creator=lambda dos:DossierTarife(dossier=dos))
>
>
>
> On Mar 28, 2012, at 6:38 AM, Christian Démolis wrote:
>
> # Many to Many
> class DossierTarife(Base):
>     __tablename__ = 'tarifer_dossier'
>     IdDossier = Column(Integer, ForeignKey('dossier.IdDossier'),
> primary_key=True)
>     IdAt = Column(Integer, ForeignKey('article_tarife.IdAt'),
> primary_key=True)
>
>     dossier = relationship(Dossier, backref=backref("tarifer_dossier",
> cascade="all, delete-orphan"))
>     article_tarife = relationship(ArticleTarife,
> backref=backref("tarifer_dossier"))
>
> class Dossier(Base):
>     __tablename__ = 'dossier'
>     IdDossier = Column('IdDossier', Integer, primary_key=True)
>    ...
>
> class ArticleTarife(Base):
>     __tablename__ = 'article_tarife'
>     IdAt = Column('IdAt', Integer, primary_key=True)
>    ...
>
> Dossier.LesTar = association_proxy("tarifer_dossier", "article_tarife")
> ArticleTarife.LesTar = association_proxy("tarifer_dossier", "dossier")
>
> *I do my simulation with this*
>         print "====================================="
>         d =
> model.session.query(model.Dossier).filter(model.Dossier.IdDossier==500315).first()
>         print d.NomDossier, len(d.LesTar), d.LesTar
>
>         print "------"
>         s =
> model.session.query(model.ArticleTarife).filter(model.ArticleTarife.IdAt==366).first()
>
>         if s in d.LesTar:
>             d.LesTar.remove(s)
>         else:
>             d.LesTar.append(s)
>         print len(d.LesTar), d.LesTar
>
>         common.merge_object(d)
>         print   s.Nom or s.Valeur
>         print s.LesTar
>         print "-------------------"
>
>
>         print "========================================"
>
>
>  --
> 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.
>

-- 
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.

Reply via email to