Chip Clark
07/29/2021, 3:59 PMconst whereClause = {
{
License: {
every: {
LicenseTypeID: license
}
}
}
};
Regardless of whether I user every: or some: it pulls all the records. There is no filtering going on.
return Promise.all([
this.prisma.person.findMany({
take: perPage,
skip,
where: whereClause,
include: defaultIncludeQuery
})
Ryan
07/30/2021, 6:54 AMsome
in the filter should give the person
records that have the LicenseTypeID
equal to 3.Chip Clark
07/30/2021, 9:15 PMmodel License {
LicenseID Int @id @default(autoincrement())
PKPersonID Int
LicenseTypeID Int
LicenseNumber String? @db.VarChar(30)
LicenseYear String? @db.VarChar(4)
LicenseState String? @db.VarChar(2)
LicenseStateLong String? @db.VarChar(50)
LicenseDate DateTime? @db.Date
Note String? @db.VarChar(Max)
Active Boolean
ActiveFromDate DateTime @db.Date
ModifiedDate DateTime @db.DateTime
ModifiedBy String @db.VarChar(30)
ValidFromDate DateTime
ValidToDate DateTime
LicenseType LicenseType @relation(fields: [LicenseTypeID], references: [LicenseTypeID])
Person Person @relation(fields: [PKPersonID], references: [PKPersonID])
}
model Person {
PKPersonID Int @id @default(autoincrement())
/// The value of this field is generated by the database as: `newsequentialid()`.
PersonGUID String @db.UniqueIdentifier
LastName String @db.VarChar(30)
FirstName String @db.VarChar(30)
MiddleName String? @db.VarChar(30)
PreferredFirstName String? @db.VarChar(30)
DisplayName String? @db.VarChar(60)
IsEmployee Boolean?
Note String? @db.VarChar(Max)
Active Boolean
OfficeFloorID Int? @db.TinyInt
BiographyURL String? @db.VarChar(300)
HasBiography Boolean
HRDepartment HRDepartment? @relation(fields: [HRDepartmentID], references: [HRDepartmentID])
JobTitle JobTitle? @relation(fields: [JobTitleID], references: [JobTitleID])
OfficeLocation OfficeLocation? @relation(fields: [OfficeLocationID], references: [OfficeLocationID])
License License[]
PersonCommittee PersonCommittee[]
Phone Phone[]
@@index([PersonGUID], name: "ncl_Person_PersonGUID")
}
Chip Clark
08/02/2021, 7:46 PMRyan
08/03/2021, 10:58 AMsome
with sample data that I entered always gives me records that have those in the relation. Btw, some
only filters the items at the top level and not what you specify in include
.
include
will always include all the items in the relation. To filter inside include
, you can use where
.Chip Clark
08/03/2021, 3:40 PMexport const defaultIncludeQuery: Prisma.PersonInclude = {
License: {
select: {
LicenseID: true,
PKPersonID: true,
LicenseTypeID: true,
LicenseNumber: true,
LicenseYear: true,
LicenseState: true,
LicenseStateLong: true,
LicenseDate: true
}
},
How to I get it to show ONLY the records via the filter AND show the License information?Chip Clark
08/03/2021, 3:57 PMLicense: {
select: {
LicenseID: true,
PKPersonID: true,
where: {
LicenseTypeID: license
},
LicenseNumber: true,
LicenseYear: true,
LicenseState: true,
LicenseStateLong: true,
LicenseDate: true
}
but it's still pulling all the users with licenses.Ryan
08/04/2021, 11:52 AMsome
in the main query and where
in select
.Chip Clark
08/06/2021, 7:47 PMconst whereClause = {
License: {
some: {
LicenseTypeID: 3
}
}
}
Then create an include:
const includeClause = {
license: {}
}
Because I wanted to be able to filter on the LicenseTypeID.
I needed to create a series of IF statements where I could parse IF parameter is 2, set whereClause variable accordingly. Because I always want to include the License information, the includeClause can remain static.
The some is necessary in the where, but NOT in the include.
However, I cannot use select in the includeClause to limit the fields displayed. If I do, prisma pulls ALL records with license information, regardless of the whereClause.Ryan
08/07/2021, 12:03 PMselect
Chip Clark
08/09/2021, 8:56 PMRyan
08/10/2021, 5:55 AMthis.prisma.person.findMany({
take: perPage,
skip,
where: whereClause,
select: defaultIncludeQuery
})
This should work. So basically it would be this:
select: {
License: {
LicenseTypeID: true,
where: { LicenseTypeID: 3 }
}
}
Chip Clark
10/13/2021, 7:06 PMPerson: {
select: {
LastName: true,
FirstName: true,
MiddleName: true,
PreferredFirstName: true,
DisplayName: true,
EmploymentStatus: true,
where: {
EmploymentStatus: 'A'
}
but get this error
Unknown field `where` for select statement on model Person. Available options are listed in green.
Invalid `this.prisma.person.findMany()` invocation in
C:\Sites\AM-API-MDD\dist\app\person\person.service.js:447:32