fix(db-postgres): query has many relationships nested in row fields (#9944) (#9944)

### What?
Querying by nested to rows fields in has many relationships like this:
```ts
const result = await payload.find({
  collection: 'relationship-fields',
  where: {
    'relationToRowMany.title': { equals: 'some-title' },
  },
})
```
Where the related collection:
```ts
const RowFields: CollectionConfig = {
  slug: rowFieldsSlug,
  fields: [
    {
      type: 'row',
      fields: [
        {
          name: 'title',
          label: 'Title within a row',
          type: 'text',
          required: true,
        },
      ],
    },
  ],
}
```

was broken

### Why?
We migrated to use `flattenedFields`, but not in this specific case.
This error would be caught earlier we used `noImplictAny` typescript
rule. https://www.typescriptlang.org/tsconfig/#noImplicitAny which
wouldn't allow us to create variable like this:
```ts
let relationshipFields // relationshipFields is any here
```
Instead, we should write:
```ts
let relationshipFields: FlattenedField[]
```
We should migrate to it and `strictNullChecks` as well.

Fixes https://github.com/payloadcms/payload/issues/9534
This commit is contained in:
Sasha
2024-12-19 05:26:08 +02:00
committed by GitHub
parent 044c22de54
commit eee6432715
4 changed files with 48 additions and 2 deletions

View File

@@ -1335,6 +1335,8 @@ export interface RelationshipField {
value: string | TextField;
}[]
| null;
relationToRow?: (string | null) | RowField;
relationToRowMany?: (string | RowField)[] | null;
updatedAt: string;
createdAt: string;
}
@@ -2970,6 +2972,8 @@ export interface RelationshipFieldsSelect<T extends boolean = true> {
id?: T;
};
relationshipWithMinRows?: T;
relationToRow?: T;
relationToRowMany?: T;
updatedAt?: T;
createdAt?: T;
}