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

Remove the include option from Model.create #15233

Open
2 tasks done
ephys opened this issue Nov 4, 2022 · 5 comments
Open
2 tasks done

Remove the include option from Model.create #15233

ephys opened this issue Nov 4, 2022 · 5 comments
Labels
good first issue For issues. An issue that is a good choice for first-time contributors. type: feature For issues and PRs. For new features. Never breaking changes.

Comments

@ephys
Copy link
Member

ephys commented Nov 4, 2022

Feature Description

The include option in Model.create is counter-intuitive. I've seen many help requests (most recent: #14759) where the user expects include to select the association after the model has been created. In reality, it's used to create associated objects.

Currently, this only creates a player, not a team:

const createdPlayer = await Player.create(
  { name: "Player 1", team: { name: "My new team" } },
);

While this creates a player & a team and associates the team and the player

const createdPlayer = await Player.create(
  { name: "Player 1", team: { name: "My new team" } },
  { include: { association: 'team' } }
);

The thing is, Player already knows team is an association (associations & attributes cannot share the same name). The first example could already work, we don't need the second version.

I propose to remove the include option altogether.

Similarly, you should be able to do use the association field to link an association that already exists:

const team = await Team.create({ name: "My new team" });

const createdPlayer = await Player.create(
  { name: "Player 1", team },
);

Or that has been built but not persisted yet:

const team = Team.build({ name: "My new team" });

const createdPlayer = await Player.create(
  { name: "Player 1", team },
);

Is this feature dialect-specific?

  • No. This feature is relevant to Sequelize as a whole.

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

  • Yes, I have the time and I know how to start.

Indicate your interest in the addition of this feature by adding the 👍 reaction. Comments such as "+1" will be removed.

@ephys ephys added the type: feature For issues and PRs. For new features. Never breaking changes. label Nov 4, 2022
@ephys ephys added the good first issue For issues. An issue that is a good choice for first-time contributors. label Jan 25, 2023
@Pulkit0729
Copy link

Hi, I would like to work on the issue. Please specify if this is still open?

@ephys
Copy link
Member Author

ephys commented Jun 28, 2023

It is, we try to keep our issues up-to-date as much as possible

@Siddhant-Kashyap
Copy link

hello is it still open i would love to work on this

@WikiRik
Copy link
Member

WikiRik commented Sep 5, 2023

Yes, this is still open

@jacobmendoza
Copy link

Quickly checking if this is stuck. I see some pending changes were requested about a month ago in #16922 . Just in case I can assist in any way.

Very grateful for the work of everyone 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue For issues. An issue that is a good choice for first-time contributors. type: feature For issues and PRs. For new features. Never breaking changes.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants