Hi, I have data model with joined table inheritance + relations between classes of this joined table inheritance class hierarchy. This works well with sqlalchemy 0.5.2, but when upgrading to 0.5.4p2, i get the following exception:
sqlalchemy.exc.ArgumentError: Entity.creator and back-reference Client.entities_created are both of the same direction <symbol 'ONETOMANY>. Did you mean to set remote_side on the many-to-one side? Here is a sample test case showing my problem: First the class hierarchy schema: [image: schema.png] so Client inherits from Entity, and Entity and Client have a one to many relation (each Entity is "created" by a Client) then the code: import sqlalchemy, sqlalchemy.orm from sqlalchemy import Table, Column, Sequence, Integer, Text, Boolean, DateTime, ForeignKey from sqlalchemy.orm import mapper, relation class EntityType(object): Entity = 0 Client = 1 class Entity(object): pass class Client(Entity): pass engine = sqlalchemy.create_engine('sqlite:///:memory:', echo=True) connexion = engine.connect() metadata = sqlalchemy.MetaData() metadata.bind = engine session_maker = sqlalchemy.orm.sessionmaker(bind = engine, autoflush = True, autocommit = False) session = session_maker() entity_table = Table( 'entity', metadata, Column('id', Text, primary_key = True), Column('entity_type', Integer, nullable = False, index = True), Column('id_creator', Text, ForeignKey('entity.id'), nullable = False, index = True), Column('description', Text)) client_table = Table( 'client_data', metadata, Column('id', Text, ForeignKey('entity.id'), primary_key = True), Column('data', Text)) metadata.create_all() connexion.execute(entity_table.insert(), [{ 'id': 'root', 'id_creator': 'root', 'entity_type': EntityType.Client, 'description': 'Lorem ipsum' }]) connexion.execute(client_table.insert(), [{ 'id': 'root', 'data': 'dolor sit amet'}]) mapper(Entity, entity_table, polymorphic_on = entity_table.c.entity_type, polymorphic_identity = EntityType.Entity, properties = { 'creator': relation(Client, collection_class = set, primaryjoin = entity_table.c.id_creator == entity_table.c.id, foreign_keys = [entity_table.c.id_creator], backref = sqlalchemy.orm.backref('entities_created', foreign_keys = [entity_table.c.id]))}) mapper(Client, client_table, inherits = Entity, polymorphic_identity = EntityType.Client) root = session.query(Client).get('root') when running on 0.5.2, everything is ok. when running on 0.5.4 i get the following stack trace: Traceback (most recent call last): File "test.py", line 63, in <module> root = session.query(Client).get('root') File "/usr/lib/pymodules/python2.5/sqlalchemy/orm/session.py", line 895, in query return self._query_cls(entities, self, **kwargs) File "/usr/lib/pymodules/python2.5/sqlalchemy/orm/query.py", line 91, in __init__ self._set_entities(entities) File "/usr/lib/pymodules/python2.5/sqlalchemy/orm/query.py", line 100, in _set_entities self.__setup_aliasizers(self._entities) File "/usr/lib/pymodules/python2.5/sqlalchemy/orm/query.py", line 114, in __setup_aliasizers mapper, selectable, is_aliased_class = _entity_info(entity) File "/usr/lib/pymodules/python2.5/sqlalchemy/orm/util.py", line 492, in _entity_info mapper = class_mapper(entity, compile) File "/usr/lib/pymodules/python2.5/sqlalchemy/orm/util.py", line 567, in class_mapper mapper = mapper.compile() File "/usr/lib/pymodules/python2.5/sqlalchemy/orm/mapper.py", line 658, in compile mapper._post_configure_properties() File "/usr/lib/pymodules/python2.5/sqlalchemy/orm/mapper.py", line 687, in _post_configure_properties prop.init() File "/usr/lib/pymodules/python2.5/sqlalchemy/orm/interfaces.py", line 408, in init self.do_init() File "/usr/lib/pymodules/python2.5/sqlalchemy/orm/properties.py", line 717, in do_init self._post_init() File "/usr/lib/pymodules/python2.5/sqlalchemy/orm/properties.py", line 1015, in _post_init self.backref.compile(self) File "/usr/lib/pymodules/python2.5/sqlalchemy/orm/properties.py", line 1174, in compile prop._add_reverse_property(self.key) File "/usr/lib/pymodules/python2.5/sqlalchemy/orm/properties.py", line 708, in _add_reverse_property " Did you mean to set remote_side on the many-to-one side ?" % (self, other, self.direction)) sqlalchemy.exc.ArgumentError: Entity.creator and back-reference Client.entities_created are both of the same direction <symbol 'ONETOMANY>. Did you mean to set remote_side on the many-to-one side ? I looked at other mails mentionning this exception (notably: http://groups.google.com/group/sqlalchemy/browse_thread/thread/232305afeab6ea18/6d10fe9712b3fdef?lnk=gst&q=both+of+the+same+direction#6d10fe9712b3fdefand http://groups.google.com/group/sqlalchemy/browse_thread/thread/d183b378c38448bf/0d96e44d92d7a45d?lnk=gst&q=both+of+the+same+direction#0d96e44d92d7a45d) so i added the explicit foreign_keys declaration in the backref 'entities_created', but the problem is still there. any help appreciated [?] --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---
<<inline: schema.png>>
<<inline: 330.gif>>