[Sqlalchemy-tickets] Issue #3189: Combining association proxy and ordering list does not work (zzze
Brought to you by:
zzzeek
|
From: Wichert A. <iss...@bi...> - 2014-09-08 13:07:27
|
New issue 3189: Combining association proxy and ordering list does not work https://bitbucket.org/zzzeek/sqlalchemy/issue/3189/combining-association-proxy-and-ordering Wichert Akkerman: I want to create an ordered many-to-many relationship, where I only really care about the order from one side of the relationship. I tried to model that by creating a relationship using `ordering_list`, and adding an `association_proxy` on top of that. That works fine when adding items to the list, but fails when trying to remove items from the list. I have attached a small python script that reproduces the error. This is the essential part of it: ```python class FolderImage(BaseObject): __tablename__ = 'folder_image' image_id = schema.Column(types.Integer(), schema.ForeignKey('image.id'), primary_key=True) folder_id = schema.Column(types.Integer(), schema.ForeignKey('folder.id'), primary_key=True) position = schema.Column(types.Integer()) def __init__(self, image=None, **kw): BaseObject.__init__(self, image_id=image.id, **kw) class Image(BaseObject): __tablename__ = 'image' id = schema.Column(types.Integer(), primary_key=True, autoincrement=True) class Folder(BaseObject): __tablename__ = 'folder' id = schema.Column(types.Integer(), primary_key=True, autoincrement=True) _images = orm.relationship('FolderImage', order_by=[FolderImage.position], collection_class=ordering_list('position')) images = association_proxy('_images', 'image') img = Image() folder = Folder(images=[img]) session.add(folder) session.flush() folder.images = [img] session.flush() ``` Running this results in: ``` sqlalchemy.exc.IntegrityError: (IntegrityError) NOT NULL constraint failed: folder_image.image_id u'INSERT INTO folder_image (folder_id, position) VALUES (?, ?)' (1, 0) ``` I am wondering if this is a regression since I apparently managed to do this a couple of years ago (see [this post](https://groups.google.com/forum/#!topic/sqlalchemy/S4_8PeRBNJw). |