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(core): fix returning clause for upsert with embeddables #4427

Merged
merged 2 commits into from
Jun 7, 2023

Conversation

jsprw
Copy link
Contributor

@jsprw jsprw commented Jun 7, 2023

…hen upserting with embeddables

Currently, when you run upsert on an entity with an embeddable, the name of the embeddable is included in the returning statement and causing InvalidFieldNameException.

The produced query without the change:

insert into `foo_bar_with_embeddable` (`_id`) values (1) on conflict (`_id`) do nothing returning `fooBarEmbeddable`, `foo_bar_embeddable_name`;

test('em.upsert(entity) with embeddable', async () => {
const testEntity = orm.em.create(FooBarWithEmbeddable, { fooBarEmbeddable: {} });

const insertedEntity = await orm.em.upsert(FooBarWithEmbeddable, testEntity);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since you pass in entity instance you can just do upsert(testEntity), also testEntity === insertedEntity, the return value makes sense only with the POJO signature

Copy link
Contributor Author

@jsprw jsprw Jun 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it, basically anything can be done here. It's just to test that the upsert and upsertMany queries run successfully (not throw an InvalidFieldNameException).

@codecov
Copy link

codecov bot commented Jun 7, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.03 🎉

Comparison is base (fa1c696) 99.61% compared to head (f13ae83) 99.64%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4427      +/-   ##
==========================================
+ Coverage   99.61%   99.64%   +0.03%     
==========================================
  Files         214      214              
  Lines       14179    14179              
  Branches     3358     3358              
==========================================
+ Hits        14124    14129       +5     
+ Misses         54       49       -5     
  Partials        1        1              
Impacted Files Coverage Δ
packages/knex/src/AbstractSqlDriver.ts 99.81% <100.00%> (ø)

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@B4nan B4nan changed the title fix(core): fix upsert on platforms with returning statements broken w… fix(core): fix returning clause for upsert with embeddables Jun 7, 2023
@B4nan B4nan merged commit b9682f0 into mikro-orm:master Jun 7, 2023
11 of 12 checks passed
@B4nan
Copy link
Member

B4nan commented Jun 7, 2023

Thanks!

@jsprw jsprw deleted the upsert-with-embeddables branch June 9, 2023 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants