Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow for complex jsonb primary key columns #6834

Merged
merged 2 commits into from
Oct 6, 2020

Conversation

Maddimax
Copy link
Contributor

@Maddimax Maddimax commented Oct 2, 2020

Entities with 'jsonb' primary key are not correctly returned. ( see #6833 )

This PR adds a fix and tests for Issue #6833

Marcus Tillmanns added 2 commits October 5, 2020 10:35
When using PrimaryColumn with a 'jsonb' type column
( on a postgres database ) the RawSqlResultsToEntityTransformer
would simply convert the key to '[object Object]' instead of a
unique value based on the key value. It would then wrongly consider each
entity as having the same key.

To allow for complex keys the transformer now uses JSON.stringify()
to convert the keys value if they are of type obejct to a unique
string that can be compared
to other entities.

fixes typeorm#6833
These tests verify that Entities with jsonb primary columns are correctly
converted to Entites
@Maddimax Maddimax changed the title Fixed https://github.com/typeorm/typeorm/issues/6833 fix: allow for complex jsonb primary key columns Oct 5, 2020
@pleerock pleerock merged commit f95e9d8 into typeorm:master Oct 6, 2020
@pleerock
Copy link
Member

pleerock commented Oct 6, 2020

Thank you!

@imnotjames imnotjames added the hacktoberfest-accepted label hacktoberfest label Oct 7, 2020
zaro pushed a commit to zaro/typeorm that referenced this pull request Jan 12, 2021
* fix: allow for complex jsonb primary key columns

When using PrimaryColumn with a 'jsonb' type column
( on a postgres database ) the RawSqlResultsToEntityTransformer
would simply convert the key to '[object Object]' instead of a
unique value based on the key value. It would then wrongly consider each
entity as having the same key.

To allow for complex keys the transformer now uses JSON.stringify()
to convert the keys value if they are of type obejct to a unique
string that can be compared
to other entities.

fixes typeorm#6833

* test: add tests for jsonb primarykey columns

These tests verify that Entities with jsonb primary columns are correctly
converted to Entites
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest-accepted label hacktoberfest
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants