Handle many to many relationship

89 views
Skip to first unread message

Christian Démolis

unread,
Mar 15, 2012, 7:38:26 AM3/15/12
to sqlalchemy
Hi all,

DossierTarife = Table('tarifer_dossier', Base.metadata,
    Column('IdDossier', Integer, ForeignKey('dossier.IdDossier')),
    Column('IdAt', Integer, ForeignKey('article_tarife.IdAt'))
)

Dossier.LesTar = relation(ArticleTarife, secondary=DossierTarife, backref=backref('dossier'))
ArticleTarife.LesTar = relation(Dossier, secondary=DossierTarife, backref=backref('article_tarife'))

When i want to change a many to many relation, the tutorial says that i must add object in the relationship (list) :
self.tarif_cible.LesTar.append(d)

where d is an instance of Dossier. But Dossier is an heavy table, so object is heavy too.

Is it any other simple way to change a many to many association (example : directly access DossierTarife table) ???

Thx in advance,

Chris

zz elle

unread,
Mar 15, 2012, 7:26:28 PM3/15/12
to sqlal...@googlegroups.com
Hi,

You can define a SA object associated to the table tarife_dossier:
  - you set its IdDossier (IdAt) attributes to its associated dossier (article) id
  - or you set dossier (article_tarife) to its associated dossier (articke) object
and you save it !


PS: tarife ou tarif ?

Christian Démolis

unread,
Mar 19, 2012, 4:23:37 AM3/19/12
to sqlal...@googlegroups.com
Thanks a lot, i will try it.

Chris

2012/3/16 zz elle <zze...@gmail.com>
--
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/FZb31d8fPMcJ.
To post to this group, send email to sqlal...@googlegroups.com.
To unsubscribe from this group, send email to sqlalchemy+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.

Reply all
Reply to author
Forward
0 new messages