python - Many-to-many relations from table to itself in SQLAlchemy -


i'm using sqlalchemy represent relationship between authors. i'd have authors related other authors (coauthorshp), data in relation, such author a can find coauthors.

how done between 2 different objects this:

class association(base):     __tablename__ = 'association'     left_id = column(integer, foreignkey('left.id'), primary_key=true)     right_id = column(integer, foreignkey('right.id'), primary_key=true)     extra_data = column(string(80))     child = relationship('child', backref='parent_assocs')  class parent(base):     __tablename__ = 'left'     id = column(integer, primary_key=true)     children = relationship('association', backref='parent')  class child(base):     __tablename__ = 'right'     id = column(integer, primary_key=true) 

but how in case?

the nature of coauthorship is bidirectional. so, when insert tuple (id_left, id_right) coauthorship table through coauthoship object, there way insert reverse relation easily? i'm asking because want use association proxies.

if you'd literally have pairs of rows in association, is, every id_left, id_right that's inserted, insert id_right, id_left, you'd use attribute event listen append events on either side, , produce append in other direction.

if want able navigate between parent/child in either direction, single row of id_left, id_right sufficient. examples in docs regarding kind of mapping illustrate whole thing.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -