premieroctet / next-admin

▲ Full-featured admin for Next.js and Prisma
https://next-admin.js.org
MIT License
292 stars 13 forks source link

Bug when trying to add relations in edit form #228

Closed ogoldberg closed 5 months ago

ogoldberg commented 5 months ago

using version "@premieroctet/next-admin": "^3.6.1"

At one point this was working fine. I have an Employer model and a Job model. An Employer has many Jobs. This is setup using the Prisma implicit relation structure.

Before, when I was creating a new job the employer field was working seamlessly. I could easily search for and add an employer to a job. I don't know what happened, but I can no longer get it to work.

This is happening with all relation fields, so this is just an example. Everything was working, now none of them work

Here's my relevant nextadmin code:

 const props = await getPropsFromParams({
    params: params.nextadmin,
    searchParams,
    options: {
      basePath: '/admin',
      model: {
        Job: {
          toString: (job) => `${job.title}`,
          edit: {
            display: [
              'title',
              'description',
              'employer',
              'union',
              'benefits',
              'industries',
              'commutingRequirement',
              'englishProficiency',
              'city',
              'zipCode',
              'datePosted',
              'validThrough',
              'employmentType',
              'salaryMin',
              'salaryMax',
              'salaryUnit',
              'email',
              'yearsOfExperience',
              'numberOfOpenings',
              'tags',
            ],
            fields: {
              description: {
                format: 'richtext-html',
              },
              employer: {},
            },
          },
          list: {
            display: [
              'title',
              'employer',
              'union',
              'city',
              'tags',
              'createdAt',
            ],
            fields: {
              employer: {
                formatter: (value: Employer) => {
                  return value?.name;
                },
              },
              city: {
                formatter: (value: City) => {
                  return value?.name;
                },
              },
              union: {
                formatter: (value: Union) => {
                  return value?.name;
                },
              },
            },
          },
        },
        Employer: {
          toString: (employer) => `${employer.name}`,
          list: {
            display: ['name'],
          },
          edit: {
            fields: {
              description: {
                format: 'richtext-html',
              },
            },
          },
        },

Here's what my prisma models look like:

model Job {
  id                   String                @id @default(cuid()) @db.VarChar(30)
  title                String
  description          String?
  datePosted           DateTime              @default(now())
  validThrough         DateTime?
  employmentType       EmploymentType?       @default(FULL_TIME)
  salaryMin            Int? //salary values should be stored in cents and should be stored after a calculation that converts to a per hour value to make it easier to search, sort, and filter
  salaryMax            Int?
  salaryUnit           SalaryUnit?
  email                String?
  yearsOfExperience    Int?
  numberOfOpenings     Int?
  city                 City?                 @relation(fields: [cityId], references: [id])
  cityId               String?               @db.VarChar(30)
  state                State?                @relation(fields: [stateId], references: [id])
  stateId              String?
  zipCode              String?
  commutingRequirement CommutingRequirement?
  englishProficiency   EnglishProficiency?
  industries           Industry[]
  benefits             Benefit[]
  union                Union?                @relation(fields: [unionId], references: [id])
  unionId              String?               @db.VarChar(30)
  employer             Employer?             @relation(fields: [employerId], references: [id])
  employerId           String?               @db.VarChar(30)
  createdAt            DateTime              @default(now())
  updatedAt            DateTime              @updatedAt
  tags                 Tag[]
}

model Employer {
  id          String     @id @default(cuid()) @db.VarChar(30)
  name        String     @unique
  description String?
  email       String?
  phone       String?
  website     String?
  logoUrl     String?
  address     String?
  city        City?      @relation(fields: [cityId], references: [id])
  cityId      String?    @db.VarChar(30)
  state       State?     @relation(fields: [stateId], references: [id])
  stateId     String?
  zipCode     String?
  jobs        Job[]
  industries  Industry[]
  benefits    Benefit[]
  unions      Union[]
  createdAt   DateTime   @default(now())
  updatedAt   DateTime   @updatedAt
  profiles    Profile[]
}

Here's what it looks like on a field that previously had the association working normally, but no longer does. image

foyarash commented 5 months ago

Hello @ogoldberg

This looks similar to #210 , it should have been a breaking change actually this is our bad there.

foyarash commented 5 months ago

v4.0.0 now throws an error if you dont pass the related action