So I am trying to do the following: class SimpleModel(object): __table_args__ = {'extend_existing': True}
id = db.Column(db.Integer, primary_key=True) class GroupEntityAttributes(SimpleModel, db.Model): __table_args__ = {'extend_existing': True} __tablename__ = 'group_entity' #Table Columns id = db.Column(db.Integer, primary_key=True) group_id = db.Column(db.Integer, db.ForeignKey('groups.id'), nullable= False) entity_id = db.Column(db.Integer, db.ForeignKey('entities.id'), nullable =False) key = db.Column(db.String) value = db.Column(db.Text) #Relationships entity = db.relationship('Entity', lazy='joined') group = db.relationship('Group') class GroupEntityAttributesPoly(GroupEntityAttributes): __mapper_args__ = {'polymorphic_on': GroupEntityAttributes.key} class GroupEntity(GroupEntityAttributesPoly): __mapper_args__ = {'polymorphic_identity': '_has_connection'} others = db.relationship( 'GroupEntityAttributes', primaryjoin=and_( remote(foreign(GroupEntityAttributes.group_id)) == GroupEntityAttributes.group_id, remote(foreign(GroupEntityAttributes.entity_id)) == GroupEntityAttributes.entity_id, ) ) When I try to load the model GroupEntity I get an error: ArgumentError: Can't determine relationship direction for relationship ' GroupEntity.others' - foreign key columns within the join condition are present in both the parent and the child's mapped tables. Ensure that only those columns referring to a parent column are marked as foreign, either via the foreign() annotation or via the foreign_keys argument. I am not sure how to overcome this error. Would appreciate any help. Best, Anton. On Tuesday, September 9, 2014 1:10:40 PM UTC-7, Anton wrote: > > Trying to use with multiple table mapping. > > On Tuesday, September 9, 2014 1:03:25 PM UTC-7, Anton wrote: >> >> Hi, >> >> I need some help choosing the right pattern for the models I have. I have >> the following tables: >> Entity (INT id, VARCHAR name) >> Group (INT id, VARCHAT name) >> GroupEntityAttributes(INT entity_id, INT group_id, VARCHAR key, VARCHAR >> name) >> >> Entity and Group models are pretty straight forward. But >> GroupEntityAttributes represents Entity within some group with custom >> attributes added, so it resembles this pattern ( >> https://bitbucket.org/zzzeek/sqlalchemy/src/374173e89d4e21a75bfabd8a655d17c247b6f1fc/examples/vertical/dictlike.py?at=master >> >> ), the only difference is that there is an additional foreign key. >> I wonder if there is any approach I can use to adapt vertical pattern for >> my needs without modifying tables. >> >> Best, >> Anton. >> >> >> -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.