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

feat(utils): infer primaryKeys from a DML model #7839

Merged
merged 7 commits into from
Jun 26, 2024

Conversation

riqwan
Copy link
Contributor

@riqwan riqwan commented Jun 25, 2024

what:

  • depending on other properties in a DML model, we infer primaryKeys between id properties and primaryKey-able properties.
Example:
  Model 1:
    id: model.id() -> primary key
    code: model.text()

  Model 2:
    id: model.id()
    code: model.text().primaryKey() -> primary key

  Model 3:
    id: model.id()
    code: model.text().primaryKey() -> composite primary key
    name: model.text().primaryKey() -> composite primary key

Copy link

vercel bot commented Jun 25, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
medusa-dashboard ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 26, 2024 9:17am
3 Ignored Deployments
Name Status Preview Comments Updated (UTC)
api-reference ⬜️ Ignored (Inspect) Jun 26, 2024 9:17am
docs-ui ⬜️ Ignored (Inspect) Visit Preview Jun 26, 2024 9:17am
medusa-docs ⬜️ Ignored (Inspect) Visit Preview Jun 26, 2024 9:17am

Copy link

changeset-bot bot commented Jun 25, 2024

⚠️ No Changeset found

Latest commit: 4dfb24e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

continue
}

if (parsed.dataType.name === "id") {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: for consistency and make it easier can you use the same approach as the other ones and if there is no type you can add a symbol.for to which we can refer too without being shown in the auto completion and then we can use it every time we need without having to think about which value to compare to know that it is an id.

You can look at the dml, properties and relations they all provide a static method ☺️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I gave this a shot, but doesn't look nice when i tried it. Lets pair on this in the next PR. 👍🏻

@kodiakhq kodiakhq bot merged commit 4945c79 into develop Jun 26, 2024
20 checks passed
@kodiakhq kodiakhq bot deleted the feat/infer-primary-keys branch June 26, 2024 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants