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

Query failed with linked model #9168

Open
darara47 opened this issue Sep 17, 2024 · 1 comment
Open

Query failed with linked model #9168

darara47 opened this issue Sep 17, 2024 · 1 comment

Comments

@darara47
Copy link

Bug report

Describe the bug

When running a query that links the CustomerModule and BadgeModule in a custom Medusa module, an error occurs. The system generates a SQL query that targets a non-existent table due to incorrect capitalization in the table name. Specifically, it attempts to query "customer_customer_badgesmodule_badge", but the correct table is "customer_customer_badgesModule_badge" (note the capitalization of badgesModule).

System information

Medusa version (including plugins): 1.20.6-preview-20240917110030
Node.js version: v20.11.1
Database: PostgreSQL 15.2
Operating system: MacOS Sonoma
Browser (if relevant):

Steps to reproduce the behavior

  1. Create custom module:
export const BADGES_MODULE = "badgesModule";
  1. Define a link between modules:
export default defineLink(
  {
    linkable: CustomerModule.linkable.customer,
    isList: true,
  },
  {
    linkable: BadgeModule.linkable.badge,
    isList: true,
  }
);
  1. Run the following query:
const { data: badges } = await query.graph({
  entity: "badge",
  fields: ["id", "name", "customers.*"],
});
  1. An error occurs when the query is executed.

Expected behavior

The query should execute and return the requested data, including the linked model (badge with associated customers).

Screenshots

Zrzut ekranu 2024-09-17 o 15 13 54

Additional context

The issue appears to stem from the query generated by the system:

select "l0"."badge_id", "l0"."customer_id" 
from "public"."customer_customer_badgesmodule_badge" as "l0" 
where "l0"."deleted_at" is null and "l0"."badge_id" in ('1', '2', '3', '4', '5')

The query is targeting the table "customer_customer_badgesmodule_badge", which does not exist. The correct table name should be "customer_customer_badgesModule_badge" (note the capitalization of badgesModule).

Changing the table name manually using pgAdmin to "customer_customer_badgesmodule_badge" resolves the issue and the query returns the correct data.

@riqwan
Copy link
Contributor

riqwan commented Sep 18, 2024

Hey @darara47,

We had a regression in one of our releases, which has already been fixed, can you upgrade to the latest preview version, run npx medusa migrations run && npx medusa links sync and try again?

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

2 participants