Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Non default Column name causes get_primary_key to fail. #44
Say you have a model:
get_primary_key will return AuthorId as the primary key, but the attribute that's actually desired is author_id. When I go go to serialize a BookSchema (with a many relationship on authors), the list of Author primary keys incorrectly gets filled with None. Using the below snippet instead solves the issue for me:
Would love some input here on whether this all makes sense.
Makes sense to me--thanks for catching this. I proposed a slightly simpler fix in #45. It's basically the same as your solution, but a little shorter:
def get_primary_keys(model): """Get primary key properties for a SQLAlchemy model. :param model: SQLAlchemy model class """ mapper = model.__mapper__ return [ mapper.get_property_by_column(column) for column in mapper.primary_key ]
Would you mind checking out the patch and verifying that it resolves the issue you encountered?