Flask-SQLAlchemy dà un example di come creare una relazione molti a molti. È fatto tra due diversi tavoli.Crea molti a molti su un tavolo
È possibile creare una relazione molti a molti sullo stesso tavolo? Ad esempio una sorella può avere molte sorelle, che avrebbero anche molte sorelle. Ho provato:
girl_sister_map = db.Table('girl_sister_map',
db.Column('girl_id',
db.Integer,
db.ForeignKey('girl.id')),
db.Column('sister_id',
db.Integer,
db.ForeignKey('girl.id')))
class Girl(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String)
sisters = db.relationship('Girl',
secondary=girl_sister_map,
backref=db.backref('othersisters', lazy='dynamic'))
Ma quando provo ad aggiungere una sorella per una ragazza ottengo:
sqlalchemy.exc.AmbiguousForeignKeysError: Could not determine join condition between parent/child tables on relationship Girl.sisters - there are multiple foreign key paths linking the tables via secondary table 'girl_sister_map'. Specify the 'foreign_keys' argument, providing a list of those columns which should be counted as containing a foreign key reference from the secondary table to each of the parent and child tables.
questo è possibile? Come dovrei farlo?