Skip to content

Polymophic Models: findMany with orderBy not working for base model properties #1755

@zupamario

Description

@zupamario

Description and expected behavior

It appears that findMany on concrete models does not support ordering by base model properties.

As an example I created a simplified polymorphic model like the following:

model Content {
  id Int @id @default(autoincrement())
  createdAt DateTime @default(now())
  contentType String

  @@delegate(contentType)
}

model Post extends Content {
  title String
}

model Video extends Content {
  name String
  duration Int
}

Assuming my frontend now needs to show a table of all posts ordered by createdAt time.
This is currently not possible with a simple findMany call like this:

db.post.findMany({orderBy: [{createdAt: "asc"}]})
name: 'PrismaClientValidationError',
  clientVersion: '5.18.0',
  internalStack: 'Error calling enhanced Prisma method `post.findMany`: \n' +
    'Invalid `prisma.post.findMany()` invocation:\n' +
    '\n' +
    '{\n' +
    '  orderBy: [\n' +
    '    {\n' +
    '      createdAt: "asc"\n' +
    '    }\n' +
    '  ],\n' +
    '  where: {\n' +
    '    AND: []\n' +
    '  },\n' +
    '  include: {\n' +
    '    delegate_aux_content: {}\n' +
    '  }\n' +
    '}\n' +
    '\n' +
    'Unknown argument `createdAt`. Available options are marked with ?.\n' +
    '    at Generator.next (<anonymous>),\n' +

I was expecting this to work because the documentation only mentions count, aggregate, and groupBy as not supported.
Any help would be much appreciated.

Environment (please complete the following information):

  • ZenStack version: 2.6.2
  • Prisma version: 5.18.0
  • Database type: Postgresql

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions