Repository navigation
Creating duplicate tags? #12607
Replies: 1 comment
|
It throws. It doesn't skip the duplicate or return the existing tag. .indexes([
{ name: "IDX_tag_value_unique", on: ["value"], unique: true, where: "deleted_at IS NULL" },
])So Postgres rejects the insert with a unique violation, and the repository's
For get-or-create, list first and create only the missing values: const existing = await productModule.listProductTags({ value: values })
const have = new Set(existing.map((t) => t.value))
const created = await productModule.createProductTags(
values.filter((v) => !have.has(v)).map((value) => ({ value }))
)A soft-deleted tag doesn't block creating a new one with the same value, because of the Not verified: I read this in the source but didn't run it, so the exact error text may differ slightly. |
Uh oh!
There was an error while loading. Please reload this page.
Hello Medusa team,
I can see in database that
ProductTagsare unique by theirvaluefield.What happens if I invoke
createProductTagswith a value that already exists? Does it throw an error? Is it skipped and the existing tag returned?I coulnd't find this behaviour documented
See https://docs.medusajs.com/resources/references/product/createProductTags
Thanks!
All reactions