I have a junction table which holds references to other two tables. What I want is to remove this refrence from the junction table. In the junction we can have more then one item from a geven type for one plane. The problem is that when I remove a given item all items from the same type are moved.
How I can remove only one item from the junction table?
Here is my database structure.
class Item(object):
pass
class Plane(object):
pass
class PlaneItem(object):
pass
planeMeta = Table("planes",
Column("plane_id", Integer, primary_key = True)
)
itemMeta = Table("items",
Column("item_id", Integer, primary_key = True)
)
planeItem = Table("planes_items",
Column("planes_items_id", Integer, primary_key = True)
Column("plane_id", Integer, ForeinKey("planes.plane_id"))
Column("item_id", Integer, ForeinKey("items.item_id"))
)
mapper(Plane, planeMeta, properties={
"items": relationship(Item, planeItem, lazy="dynamic")
})
Adding a new Item.
plane = dbSess.query(Plane).filter(Plane.plane_id == my_plane_id).one()
newItem = dbSess.query(Item).filter(Item.item_id == my_new_item).one()
plane.items.append(newItem)
Removing an item.
itemForRemoving = myPlane.items.filter(item_id==4)
myPlane.items.remove(itemForRemoving)