Use SQLAlchemy-provided way to get primary_key, as a solution of the problem when a model is mapped against a SQLAlchemy Join object.