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

createMany dosen't insert realation #15340

Closed
MHZarei opened this issue Jan 3, 2023 · 5 comments
Closed

createMany dosen't insert realation #15340

MHZarei opened this issue Jan 3, 2023 · 5 comments
Labels
issue: feature request Issue suggesting a new feature

Comments

@MHZarei
Copy link

MHZarei commented Jan 3, 2023

Bug report

Required System information

  • Node.js version: v16.16.0
  • NPM version:
  • Strapi version: 4.5.5
  • Database: Sqlite
  • Operating system: ubuntu 22.04

Describe the bug

If your entity have relation with another entity, and on createMany use id of it to insert, it doesn't insert relation data!
For example this code just insert rate and date and the user information doesn't inserted.

await strapi.db.query('api::rate.rate').createMany({
      data: [{ date: 1672788743747, user: 1, rate: 1 },
                 { date: 1672788743747, user: 2, rate: 2 },
                 { date: 1672788743747, user: 3, rate: 5 },
        ],
    }); 

Expected behavior

I expected the relation information (for above example: user) saved in the database;

@derrickmehaffy
Copy link
Member

These will need to be an array of ids that already exist or you will need to loop through and create them beforehand and grab the IDs. We don't support creating nested data at any level.

@derrickmehaffy derrickmehaffy added the issue: feature request Issue suggesting a new feature label Jan 4, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Jan 4, 2023

This is a templated message

Hello @MHZarei,

First thank you for reporting this feature need.
To manage feature requests and the Strapi roadmap, we are using Canny.
You will be able to access the Public Roadmap here: https://feedback.strapi.io.

In your message, please mention the URL of this thread in case some messages are posted there. But the most important is to have your feedback posted on our feedback/roadmap site.
The product team is reading EVERY comment, that really helps us to develop the project in the right direction. We are keeping all feature requests and project insights in one place, our feedback website.

In order to keep our GitHub issues clean and for valid bug reports this issue will be marked as closed, but please feel free to continue the discussion with other community members here.

Thank you for your insight and have a good day.

@github-actions github-actions bot closed this as completed Jan 4, 2023
@dzcpy
Copy link

dzcpy commented Jan 17, 2023

@derrickmehaffy
This is actually a bug not a feature request. It doesn't save any relations (using id), when this entity has already been created and is available with that relation ID.

@dzcpy
Copy link

dzcpy commented Jan 17, 2023

To prove it, try to create a content type named post, and add a relation author to the user (user_permission) entity. Then try this:

await strapi.db.query('api::post.post').createMany({
  data: [{ author: 1 }],
});

It doesn't save the author field even if user 1 does exist.

@alicanso
Copy link

why is it closed? problem is still exist?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue: feature request Issue suggesting a new feature
Projects
Archived in project
Development

No branches or pull requests

4 participants