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?