Sqlalchemy: Many to Many relationship error
Posted
by 1001010101
on Stack Overflow
See other posts from Stack Overflow
or by 1001010101
Published on 2010-05-13T03:53:28Z
Indexed on
2010/05/13
4:04 UTC
Read the original article
Hit count: 168
sqlalchemy
|python
Dear everyone, I am following the Many to many relationship described on http://www.sqlalchemy.org/docs/mappers.html#many-to-many
#This is actually a VIEW
tb_mapping_uGroups_uProducts = Table( 'mapping_uGroups_uProducts', metadata,
Column('upID', Integer, ForeignKey('uProductsInfo.upID')),
Column('ugID', Integer, ForeignKey('uGroupsInfo.ugID'))
)
tb_uProducts = Table( 'uProductsInfo', metadata,
Column('upID', Integer, primary_key=True)
)
mapper( UnifiedProduct, tb_uProducts)
tb_uGroupsInfo = Table( 'uGroupsInfo', metadata,
Column('ugID', Integer, primary_key=True)
)
mapper( UnifiedGroup, tb_uGroupsInfo, properties={
'unifiedProducts': relation(UnifiedProduct, secondary=tb_mapping_uGroups_uProducts, backref="unifiedGroups")
})
where the relationship between uProduct and uGroup are N:M.
When I run the following
sess.query(UnifiedProduct).join(UnifiedGroup).distinct()[:10]
I am getting the error:
sqlalchemy.exc.ArgumentError: Can't find any foreign key relationships between 'uProductsInfo' and 'uGroupsInfo'
What am I doing wrong?
© Stack Overflow or respective owner