title: Flask-SqlAlchemy Many-To-Many relationship with duplicates allowed
body: <p>I have an <code>Order - FoodItem</code> Many-To-Many relationship that is as follows:</p>
  
  <pre><code>association_table = db.Table('association', db.Model.metadata,
      db.Column('left_id', db.Integer, db.ForeignKey('orders.order_id')),
      db.Column('right_id', db.Integer, db.ForeignKey('fooditems.fooditem_id'))
  )
  
  class OrderModel(ReviewableModel):
      __tablename__ = 'orders'
      order_id = db.Column(db.Integer, db.ForeignKey('reviewables.id'), primary_key=True)
      food_items = db.relationship("FoodItemModel", secondary = association_table)
      __mapper_args__ = {'polymorphic_identity':'orders'}
  
  class FoodItemModel(ReviewableModel):
      __tablename__ = 'fooditems'
      fooditem_id = db.Column(db.Integer, db.ForeignKey('reviewables.id'), primary_key=True)  
      __mapper_args__ = {'polymorphic_identity':'fooditems'}
  </code></pre>
  
  <p>The user can request an order with duplicate foodItems. This is created properly, but when I save the changes to the database, the duplicates are removed. For e.g., I order 3 Pizzas:</p>
  
  <pre><code>def save_to_db(self):
      print('before: '+str(self.food_items))
      db.session.add(self)
      db.session.commit()
      print('after: '+str(self.food_items))
  </code></pre>
  
  <p>The output is like this:</p>
  
  <pre><code>before: [&lt;FoodItemModel u'Pizza'&gt;, &lt;FoodItemModel u'Pizza'&gt;, &lt;FoodItemModel u'Pizza'&gt;]
  after: [&lt;FoodItemModel u'Pizza'&gt;]
  </code></pre>
  
  <p>The association table is updated properly:</p>
  
  <pre><code>"left_id"   "right_id"
  "6"         "3"
  "6"         "3"
  "6"         "3"
  </code></pre>
  
  <p>However, the food_items in the OrderModel only contains 1 item</p>