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

Order by Relations with multiple references #7331

Closed
Tracked by #8628
Brandejs opened this issue May 28, 2021 · 4 comments · Fixed by prisma/prisma-engines#2145
Closed
Tracked by #8628

Order by Relations with multiple references #7331

Brandejs opened this issue May 28, 2021 · 4 comments · Fixed by prisma/prisma-engines#2145
Assignees
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: orderByRelation topic: postgresql
Milestone

Comments

@Brandejs
Copy link

Brandejs commented May 28, 2021

Bug description

prismaClientUnknownRequestError2 [PrismaClientUnknownRequestError]: Invalidprisma.task.findMany() invocation: Error occurred during query execution: ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Error { kind: Db, cause: Some(DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState("42804"), message: "argument of JOIN/ON must be type boolean, not type record", detail: None, hint: None, position: Some(Original(383)), where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some("parse_coerce.c"), line: Some(1156), routine: Some("coerce_to_boolean") }) }) }) at cb (/prisma-schema-orderby/node_modules/@prisma/client/runtime/index.js:35105:17) at processTicksAndRejections (internal/process/task_queues.js:93:5) { clientVersion: '2.23.0' }

How to reproduce

I prepare a simple project. There are 3 entities with composite keys. The last entity (TASK) has reference to Company and Project. I Can order tasks by Company_Name, but I cannot order them by Project_Name.
prisma-schema-orderby.zip

Expected behavior

Should order by Project_Name.

Prisma information

	/**
	 * THIS WILL THROW AN ERROR
	 */
	const tasksOrderByprojectName = await prisma.task.findMany({
		where: { deletedAt: null },
		orderBy: {
			project: {
				name: "asc",
			},
		},
	});

	/**
	 * THIS IS OK
	 */
	const tasksOrderByCompanyName = await prisma.task.findMany({
		where: { deletedAt: null },
		orderBy: {
			company: {
				name: "asc",
			},
		},
	});

Environment & setup

  • OS: Mac OS / Linux
  • Database: PostgreSQL
  • Node.js version: v14.15.4

Prisma Version

prisma               : 2.23.0
@prisma/client       : 2.23.0
Current platform     : darwin
Query Engine         : query-engine adf5e8cba3daf12d456d911d72b6e9418681b28b (at node_modules/@prisma/engines/query-engine-darwin)
Migration Engine     : migration-engine-cli adf5e8cba3daf12d456d911d72b6e9418681b28b (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core adf5e8cba3daf12d456d911d72b6e9418681b28b (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary        : prisma-fmt adf5e8cba3daf12d456d911d72b6e9418681b28b (at node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash : adf5e8cba3daf12d456d911d72b6e9418681b28b
Studio               : 0.393.0
Preview Features     : orderByRelation, selectRelationCount
@Brandejs Brandejs added the kind/bug A reported bug. label May 28, 2021
@janpio janpio added topic: orderByRelation bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. team/client Issue for team Client. and removed bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. labels May 28, 2021
@thebiglabasky
Copy link

Candidating this one for next sprint to consider moving orderByRelation out of preview.

@pantharshit00
Copy link
Contributor

I can reproduce this with 2.24.1. Thanks for the reprodution zip.

@pantharshit00 pantharshit00 added bug/2-confirmed Bug has been reproduced and confirmed. and removed bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Jun 9, 2021
@SamuelMS
Copy link

SamuelMS commented Jun 20, 2021

This issue also seems to occur in 2.25.0 when using _count (via selectRelationCount) on a model that has a composite key.

Error:
Invalid `prisma.<model>.findMany()` invocation:


Error occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Error { kind: Db, cause: Some(DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState("42804"), message: "argument of JOIN/ON must be type boolean, not type record", detail: None, hint: None, position: Some(Original(503)), where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some("parse_coerce.c"), line: Some(1154), routine: Some("coerce_to_boolean") }) }) })
     at cb (/app/node_modules/@prisma/client/runtime/index.js:33820:17)
     at processTicksAndRejections (internal/process/task_queues.js:95:5)

@matthewmueller
Copy link
Contributor

Internal Note: Candidating it since it's one of our oldest preview features 2.16.0 and we should consider looking into this before we remove the preview flag

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: orderByRelation topic: postgresql
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants