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

[BUG] - One to many relation field not shown in edit and create mode #513

Open
eng-ahmad-sameer opened this issue Jan 14, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@eng-ahmad-sameer
Copy link

Description

In the latest version, I noticed that the one-to-many relation fields are not in the edit mode.
In the SellerProfile table, I should see the

         "user",
          "country",
          "province",
          "city",
          "sellerType",
          "companyName",
          "createdAt",

I am only see the user, companyName, and createdAt

My tables:

model SellerProfile {
  id           String      @id @default(cuid())
  vwId         Int?        @unique
  userId       String
  user         User        @relation(fields: [userId], references: [id], onDelete: Cascade, name: "SellerProfileUser")
  cityId       String?
  city         City?       @relation(fields: [cityId], references: [id])
  provinceId   String?
  province     Province?   @relation(fields: [provinceId], references: [id])
  countryId    String?
  country      Country?    @relation(fields: [countryId], references: [id])
  sellerTypeId String?
  sellerType   SellerType? @relation(fields: [sellerTypeId], references: [id])
  companyName  String?
  createdAt    DateTime    @default(now())
  updatedAt    DateTime    @updatedAt

  @@unique([userId])
  @@index([cityId])
  @@index([provinceId])
  @@index([countryId])
  @@index([sellerTypeId])
}

model Country {
  id             String          @id @default(cuid())
  name           String
  iso2           String
  iso3           String
  phoneCode      String
  latitude       String?
  longitude      String?
  provinces      Province[]
  cities         City[]
  sellers        SellerProfile[]
  buyers         BuyerProfile[]
  sellerListings SellerListing[] @relation("CountryOnSellerListings")

  @@unique([iso2])
}

model Province {
  id             String          @id @default(cuid())
  name           String
  code           String
  countryId      String
  country        Country         @relation(fields: [countryId], references: [id], onDelete: Cascade)
  cities         City[]
  latitude       String?
  longitude      String?
  sellers        SellerProfile[]
  buyers         BuyerProfile[]
  sellerListings SellerListing[] @relation("ProvinceOnSellerListings")

  @@unique([countryId, code])
  @@index([countryId])
}

model City {
  id              String          @id @default(cuid())
  name            String
  provinceId      String
  province        Province        @relation(fields: [provinceId], references: [id], onDelete: Cascade)
  countryId       String
  country         Country         @relation(fields: [countryId], references: [id], onDelete: Cascade)
  latitude        String?
  longitude       String?
  sellers         SellerProfile[]
  buyerCity       BuyerProfile[]  @relation("CityOnBuyers")
  buyerSearchCity BuyerProfile[]  @relation("SearchCitiesOnBuyers")
  sellerListings  SellerListing[] @relation("CityOnSellerListings")

  @@unique([provinceId, countryId, name])
  @@index([provinceId])
  @@index([countryId])
}

model SellerType {
  id      String          @id @default(cuid())
  name    String
  sellers SellerProfile[]

  @@unique([name])
}

Reproduction URL

Not available

Reproduction steps

Not available

Next router

App router

Next Admin version

^7.1.0

Screenshots

Not available

Next Admin options

SellerProfile: {
      title: "Profiles",
      icon: "UserIcon",
      toString: (sellerProfile) =>
        `${sellerProfile.user.name || ""} seller profile`,
      list: {
        display: [
          "user",
          "country",
          "province",
          "city",
          "sellerType",
          "companyName",
          "createdAt",
        ],
        fields: {
          user: {
            formatter: (value) => value?.name,
            sortBy: "name",
          },
          country: {
            formatter: (value) => value.name,
            sortBy: "name",
          },
          province: {
            formatter: (value) => value.name,
            sortBy: "name",
          },
          city: {
            formatter: (value) => value.name,
            sortBy: "name",
          },
          sellerType: {
            formatter: (value) => value?.name,
            sortBy: "name",
          },
          createdAt: {
            formatter: (value) => formatDate(value),
          },
        },
        search: ["user.name", "user.email"],
      },
      edit: {
        display: [
          "user",
          "country",
          "province",
          "city",
          "sellerType",
          "companyName",
          "createdAt",
        ],
        fields: {
          user: {
            required: true,
          },
          country: {
            required: true,
            optionFormatter: (value) => value.name,
          },
          province: {
            required: true,
            optionFormatter: (value) => value.name,
          },
          city: {
            required: true,
            optionFormatter: (value) => value.name,
          },
          sellerType: {
            required: true,
          },
        },
      },
      aliases: {
        sellerType: "Seller type",
        companyName: "Company name",
        createdAt: "Created at",
      },
    },
  Country: {
      title: "Countries",
      icon: "GlobeAltIcon",
      toString: (country) => `${country.name}`,
      list: {
        display: [
          "name",
          "iso2",
          "phoneCode",
          "provinces",
          "buyers",
          "sellers",
        ],
        search: ["name", "iso2", "phoneCode"],
        copy: ["name", "iso2", "phoneCode"],
      },
      edit: {
        display: ["name", "iso2", "phoneCode"],
      },
    },
    Province: {
      title: "Provinces",
      icon: "MapIcon",
      toString: (province) => `${province.name}`,
      list: {
        display: ["name", "code", "country", "cities", "buyers", "sellers"],
        search: ["name", "code", "country.name"],
        copy: ["name", "code"],
        fields: {
          country: {
            formatter: (value) => value?.name,
            sortBy: "name",
          },
        },
      },
      edit: {
        display: ["name", "code", "country"],
      },
    },
    City: {
      title: "Cities",
      icon: "MapPinIcon",
      toString: (city) => `${city.name}`,
      list: {
        display: ["name", "province", "country", "buyerCity", "sellers"],
        search: ["name", "province.name", "country.name"],
        copy: ["name"],
        fields: {
          province: {
            formatter: (value) => value?.name,
            sortBy: "name",
          },
          country: {
            formatter: (value) => value?.name,
            sortBy: "name",
          },
        },
      },
      edit: {
        display: ["name", "province", "country"],
      },
      aliases: {
        buyerCity: "Buyers",
      },
    },

Logs

Not available

Browsers

No response

@eng-ahmad-sameer eng-ahmad-sameer added the bug Something isn't working label Jan 14, 2025
@eng-ahmad-sameer eng-ahmad-sameer changed the title [BUG] - One to many relation field not shown in edit mode [BUG] - One to many relation field not shown in edit and create mode Jan 14, 2025
@cregourd
Copy link
Collaborator

Hi @eng-ahmad-sameer, at first glance I can assume that this problem may comes from the fact that all the fields that don't display are under the @@index annotations, maybe this is a red herring but can you try removing the annotations and applying the migration to see if the problem is related to that. Also, you mention that the problem is in edit mode, haven't you encountered the same problem in create mode?

@eng-ahmad-sameer
Copy link
Author

Hey @cregourd

The issue happen for create and edit mode.
I will try to remove indexing and see if it is related.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants