Skip to content

Order by Relations with multiple references #7331

Closed
prisma/prisma-engines
#2145

Description

@Brandejs

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

Activity

  1. added
    kind/bug
    on May 28, 2021
  2. added
    bug/0-unknown
    bug/1-unconfirmed
    and removed
    bug/0-unknown
    on May 28, 2021
  3. thebiglabasky commented on Jun 8, 2021

    @thebiglabasky

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

  4. pantharshit00 commented on Jun 9, 2021

    @pantharshit00
    Contributor

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

  5. added
    bug/2-confirmed
    and removed
    bug/1-unconfirmed
    on Jun 9, 2021
  6. SamuelMS commented on Jun 20, 2021

    @SamuelMS

    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)
    
  7. matthewmueller commented on Jul 6, 2021

    @matthewmueller
    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

  8. added this to the 2.30.0 milestone on Aug 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug/2-confirmedkind/bugtopic: orderByRelationtopic: postgresql

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions