title: many to many relationship with three tables (sql-alchemy)
body: <p>I am trying to get a many to many relationship working. I have three tables</p>
  
  <pre><code>class User(db.Model):
      id = db.Column(db.Integer, primary_key=True)
      username = db.Column(db.String(64), index=True, unique=True)
  
  class Groups(db.Model):
      id = db.Column(db.Integer, primary_key=True)
      name = db.Column(db.String(1000))
  
  class Members(db.Model):
      id = db.Column(db.Integer, primary_key=True)
      user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
      group_id = db.Column(db.Integer, db.ForeignKey('groups.id'))
  </code></pre>
  
  <p>I would like to have the option group.members, which should give me all User objects which are member of that group. I implemented it the following way</p>
  
  <pre><code>members = db.relationship('User', secondary="join(Members, User, Members.user_id == User.id)", primaryjoin="and_(Groups.id == Members.group_id)") 
  </code></pre>
  
  <p>this seems to work, but when I delete a group it gives me (sometimes) the error </p>
  
  <p>AttributeError: 'Join' object has no attribute 'delete'</p>
  
  <p>so I guess this is not the right way to implement such a relation. 
  Any ideas how to do this correctly?
  thanks
  carl</p>