hi guys, i'm here again to ask more one question :...
# orm-help
b
hi guys, i'm here again to ask more one question 🙂 let me try to explain what i want to do. i've some sort of relations more or less like this.
Copy code
model Gene {
  id Int @default(autoincrement()) @id
  name String @unique
  heritage String
  createdAt DateTime @default(now())
  modifiedAt DateTime @default(now())

  @@map(name: "genes")
}

model Diagnose {
  id Int @default(autoincrement()) @id
  report_id String
  client_name String
  gender String
  birthdate String
  in_negative Boolean
  createdAt DateTime @default(now())
  modifiedAt DateTime @default(now())
  
  variants GeneVariants[]

  @@unique([report_id])
  @@map(name: "diagnosis")

}

model GeneVariants {
  id Int @default(autoincrement()) @id
  zygosity String
  localization String
  coding String
  protein String
  classification String
  transcrito String
  diagnose Diagnose @relation(fields: [diagnose_id], references: [id])
  diagnose_id Int
  gene Gene @relation(fields: [gene_id], references: [id])
  gene_id Int

  createdAt DateTime @default(now())
  modifiedAt DateTime @default(now())
  
  @@map(name: "diagnosis_genes_variants")

}

model GeneReferences {
  id Int @default(autoincrement()) @id

  explanation String

  gene Gene @relation(fields: [gene_id], references: [id])
  gene_id Int
  gender String
  
  createdAt DateTime @default(now())
  modifiedAt DateTime @default(now())

  interpretation GeneInterpretations[]
  
  @@map(name: "gene_references")

}
query example:
Copy code
public async getDiagnose(report_id: string): Promise<any> {
        const result = await this.database.instance.diagnose.findFirst({
            include: {
                variants: {
                    include: {
                        gene: {
                            include: {
                                GeneInterpretations: {
                                    where: {
                                        gender: 'how_filter_this_using_the_gender_diagnoses_top_level?'
                                    }
                                }
                            }
                        },
                    }
                },
            },
            where: {
                report_id: report_id
            }
        });
        
        
        return result;
    }
The question: how can i filter GeneInterpretations passing the top level gender?
maybe somelike this? '$diagnose.gender'
s
what you are doing should be fine I think.
Copy code
prisma.table_a.findMany({
  include: {
    table_b: {
      where: {
        gender: "female"
      }
    }
  }
})
If not, you probably need to explain the problem further as it is hard to understand what you are asking.
b
@Swapnull i'll edit the code with real code
@Swapnull maybe the real example can help to understand my problem?
the gender is on "top level result" and i want filter GeneInterpretations using this result from top level. Otherwise, i'll have to perform two queries.
s
ah. yeah, I have never managed to do that either. I don't think you can use the result from the query in the query again. We have always ended up using 2 queries for that type of thing (which I think was recommended here)
✅ 1
b
oh sadge 😞 maybe this can be a improvement for the future... perform a subquery like mongo aggregate does
and you can pass by reference the field
thanks for the help @Swapnull