Skip to content

relationsJoins enabled with @db.Json in Postgres makes the order of the JSON fields completely disappear #22479

@semoal

Description

@semoal

Bug description

We have a field called "layout" that is a JSON stored inside a template schema, we have noticed that our templates were crashing because out of order, after analysing what happened we have seen that in the database was in the correct order but after calling:

const collectionWithTemplates = await prisma.collection.findMany({ include: { template: true }})

The template object which contains a layout field that is a @db.JSON was not ordered/preserved the order correctly.

How to reproduce

Simply create an schema with a relation with json field, and fetch this field through a relation

Expected behavior

It should keep the order

Prisma information

Prisma schema

generator client {
  provider        = "prisma-client-js"
  output          = "../../../packages/prisma-client/client"
  previewFeatures = ["fullTextSearch", "tracing", "relationJoins", "nativeDistinct"]
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model Collection {
  id String @id @default(uuid()) @db.Uuid
  templateId String             @db.Uuid
  template   Template @relation(fields: [templateId], references: [id], onDelete: Cascade)
}

model Template {
  id String @id @default(uuid()) @db.Uuid
  layout       Json           @db.Json
  collections  Collection[]
}

Code to check

  const template = await prisma.collection.findFirst({
    include: {
      template: true,
    },
  });

Environment & setup

  • OS: Ubuntu/Mac
  • Database: PostgreSQL
  • Node.js version: Node 18

Prisma Version

5.7.1

Metadata

Metadata

Assignees

Labels

bug/1-unconfirmedBug should have enough information for reproduction, but confirmation has not happened yet.kind/bugA reported bug.tech/enginesIssue for tech Engines.topic: JsonScalar type `Json`topic: relationJoins

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions