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

Using updateOnDuplicate in include with bulkCreate does not work #12080

Closed
2 of 7 tasks
marinalohova opened this issue Apr 7, 2020 · 3 comments
Closed
2 of 7 tasks

Using updateOnDuplicate in include with bulkCreate does not work #12080

marinalohova opened this issue Apr 7, 2020 · 3 comments

Comments

@marinalohova
Copy link

marinalohova commented Apr 7, 2020

Issue Description

What are you doing?

I am trying to use bulkCreate with include that has updateOnDuplicate option.

await Product.bulkCreate(products, {
        updateOnDuplicate: ['name', 'description', 'subscriptionId', 'creditId'],
        include: [{
          model: Subscription,
          as: 'subscription',
          updateOnDuplicate: ['subscriptionFee', 'subscriptionReoccurrence'],
        }],
      });

My input is as following:

      const products = [
        {
          id: 70,
          subscription: {
            id: 59,
            subscriptionFee: 10,
          },
          name: 'New Plan name',
          description: '10% off',
        },
      ];

What do you expect to happen?

Nested Subscription on Product to be updated.

What is actually happening?

SQL is correctly generated. I am able to run it in in my database. However, I receive an internal server error where product.setSubscription is supposed to happen.

INSERT INTO "subscriptions" ("id","subscription_fee","created_at","updated_at") VALUES (59,10,'2020-04-07 22:33:39.324 +00:00','2020-04-07 22:33:39.324 +00:00') ON CONFLICT ("id") DO UPDATE SET "subscription_fee"=EXCLUDED."subscription_fee","subscription_reoccurrence"=EXCLUDED."subscription_reoccurrence" RETURNING *;

Stacktrace:

"TypeError: instance[include.association.accessors.set] is not a function",
" at /Users/marina.lohova/Work/graphql-server/node_modules/sequelize/lib/model.js:2663:60",

Additional context

I followed the example here for bulkCreate with include #11307

Environment

  • Sequelize version: 5.21.4
  • PostgreSQL 10.7
  • Node.js version: v12.12.0
  • Operating System: MacOS Catalina 10.15.3

Issue Template Checklist

How does this problem relate to dialects?

  • I think this problem happens regardless of the dialect.
  • I think this problem happens only for the following dialect(s):
  • I don't know, I was using PUT-YOUR-DIALECT-HERE, with connector library version XXX and database version XXX

Would you be willing to resolve this issue by submitting a Pull Request?

  • Yes, I have the time and I know how to start.
  • Yes, I have the time but I don't know how to start, I would need guidance.
  • No, I don't have the time, although I believe I could do it if I had the time...
  • No, I don't have the time and I wouldn't even know how to start.
@jeffersonveloso
Copy link

Have any solution for this problem ?

@jeffersonveloso
Copy link

Have any solution for this problem ? @srslyimthebest or @sushantdhiman

@github-actions
Copy link
Contributor

github-actions bot commented Nov 2, 2021

This issue has been automatically marked as stale because it has been open for 7 days without activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment or remove the "stale" label. 🙂

@github-actions github-actions bot added the stale label Nov 2, 2021
@github-actions github-actions bot closed this as completed Nov 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants