jjm
jjm

Reputation: 13

Keystone generating 2 different relationship schemas for exact same list code, and one doesn't appear in the other related list as a field

I have 2 lists with exactly the same fields and code, just different names. I have set them to only appear on item view of the list [videoObject] when they are not null. What happens is that one of them (Legacy_Video), never appears. I checked the item variable of the [videoObject] and legacyvideoID never appears (null or with a value), and xrvideoID always appears.

As you can see by the code there is no reason for them to have different behaviors, and there is no reason for [Legacy_Video] not showing as a field of [videoObject] list. What is happening with [videoObject] is also happening with another list [videoCastCredits] which has the exact same logic, in relationship with [XR_Video] and [Legacy_Video]. So it must be something related with [Legacy_Video] list, although the code is exactly the same as [XR_Video], that appears.

I tried everything:

Each time I do yarn install, I get an error in the end for not having schema.prisma. I then do yarn run dev and it generates everything, but the schemas that should be the same come always different and [Legacy_Video] never appears in the ui or the [item] object variable of [videoObject]. I tried it several times. It's always the same.

I wonder if there is any kind of cache that is storing some old schema, that i don't know about.

keystone generated schema.prisma:

model Legacy_Video {
  id                      String                @id @default(cuid())
  about                   String                @default("")
  performanceOrRehearsal  String
  Languages               String?
  date                    String?
  castCredits             Video_CastAndCredits? @relation("Legacy_Video_castCredits", fields: [castCreditsId], references: [id])
  castCreditsId           String?               @unique @map("castCredits")
  videoObject             VideoObject?          @relation("Legacy_Video_videoObject", fields: [videoObjectId], references: [id])
  videoObjectId           String?               @unique @map("videoObject")
  dataStatus              String
  approved                Boolean               @default(false)
  streamingUrl            String                @default("")
  dataUrl                 String                @default("")
  creativeWork            CreativeWork?         @relation("Legacy_Video_creativeWork", fields: [creativeWorkId], references: [id])
  creativeWorkId          String?               @map("creativeWork")
  associatedPersons       Person[]              @relation("Legacy_Video_associatedPersons")
  associatedOrganizations Organization[]        @relation("Legacy_Video_associatedOrganizations")

  @@index([creativeWorkId])
}

model _ {
  id                      String                @id @default(cuid())
  about                   String                @default("")
  performanceOrRehearsal  String
  Languages               String?
  date                    String?
  castCredits             Video_CastAndCredits? @relation("Video_CastAndCredits_xrVideo")
  videoObject             VideoObject?          @relation("VideoObject_xrVideo")
  dataStatus              String
  approved                Boolean               @default(false)
  streamingUrl            String                @default("")
  dataUrl                 String                @default("")
  creativeWork            CreativeWork?         @relation("XR_Video_creativeWork", fields: [creativeWorkId], references: [id])
  creativeWorkId          String?               @map("creativeWork")
  associatedPersons       Person[]              @relation("Person_xrVideo")
  associatedOrganizations Organization[]        @relation("Organization_xrVideo")

  @@index([creativeWorkId])
}

in [videoObject] list:

...group({
      label: "Related To:", 
      fields: {   
        xrVideo: relationship({
          label: 'XR Video',
          ref: 'XR_Video.videoObject',
          many: false, 
          ui: {
            createView: {
              fieldMode: ({ session, context }) => 'hidden',
            },
            itemView: {
              fieldMode: async ({ session, context, item }) => {
                console.log('ITEM XR:')
                console.log(item)

                if (item.xrVideoId != null) return 'read'

                return 'hidden'
              },
              fieldPosition: 'sidebar',          
            },
            listView: {
              fieldMode: ({ session, context }) => 'read',
            },        
          }       
        }),                    
        legacyVideo: relationship({
          label: 'Legacy Video',
          ref: 'Legacy_Video.videoObject',
          many: false, 
          ui: {
            createView: {
              fieldMode: ({ session, context }) => 'hidden',
            },
            itemView: {
              fieldMode: async ({ session, context, item }) => {
                console.log('ITEM LEGACY:')
                console.log(item)

                if (item.legacyVideoId != null) return 'read'

                return 'hidden'
              },
              fieldPosition: 'sidebar',          
            },
            listView: {
              fieldMode: ({ session, context }) => 'read',
            },        
          }       
        }),
      }
    }),

in Legacy_Video list (same as XR_Video):

export const Legacy_Video = list({
  ...
  fields:{          
    ...
    castCredits: relationship({
      label:"Cast & Credits",
      ref: 'Video_CastAndCredits.legacyVideo', 
      many: false,         
    }),    
    
    videoObject: relationship({
      label: 'Video Object',
      ref: 'VideoObject.legacyVideo', 
      many: false, 
    }),  
    
    ...
    

The prisma schema of both [XR_Video] and [Legacy_Video] should be exactly the same. And [Legacy_Video] should appear as a field of videoObject. But both don't occur.

Upvotes: 0

Views: 15

Answers (0)

Related Questions