Skip to content

Commit

Permalink
Merge pull request #409 from psteinroe/fix/aliased-pks--2
Browse files Browse the repository at this point in the history
fix: make sure that its a nested path
  • Loading branch information
psteinroe committed Mar 12, 2024
2 parents 40a6327 + de6a220 commit 19e1751
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/postgrest-core/src/delete-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
BuildNormalizedQueryOps,
buildNormalizedQuery,
} from './fetch/build-normalized-query';
import { isNestedPath } from './lib/group-paths-recursive';

export type DeleteFetcher<T extends GenericTable, R> = (
input: Partial<T['Row']>[],
Expand Down Expand Up @@ -45,7 +46,8 @@ export const buildDeleteFetcher =
const query = buildNormalizedQuery<Q>(opts);

const pkAlias = (path: string): string =>
query?.paths.find((p) => p.path === path)?.alias || path;
query?.paths.find((p) => p.path === path && !isNestedPath(p))?.alias ||
path;

if (primaryKeys.length === 1) {
const primaryKey = primaryKeys[0] as string;
Expand Down
4 changes: 3 additions & 1 deletion packages/postgrest-core/src/update-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
buildNormalizedQuery,
BuildNormalizedQueryOps,
} from './fetch/build-normalized-query';
import { isNestedPath } from './lib/group-paths-recursive';

export type UpdateFetcher<T extends GenericTable, R> = (
input: Partial<T['Row']>,
Expand Down Expand Up @@ -45,7 +46,8 @@ export const buildUpdateFetcher =
const query = buildNormalizedQuery<Q>(opts);

const pkAlias = (path: string): string =>
query?.paths.find((p) => p.path === path)?.alias || path;
query?.paths.find((p) => p.path === path && !isNestedPath(p))?.alias ||
path;

for (const key of primaryKeys) {
const value = input[key];
Expand Down

0 comments on commit 19e1751

Please sign in to comment.