MCPcopy Create free account
hub / github.com/zenstackhq/zenstack / buildJoinPairs

Function buildJoinPairs

packages/orm/src/client/query-utils.ts:267–285  ·  view source on GitHub ↗
(
    schema: SchemaDef,
    model: string,
    modelAlias: string,
    relationField: string,
    relationModelAlias: string,
)

Source from the content-addressed store, hash-verified

265}
266
267export function buildJoinPairs(
268 schema: SchemaDef,
269 model: string,
270 modelAlias: string,
271 relationField: string,
272 relationModelAlias: string,
273): [string, string][] {
274 const { keyPairs, ownedByModel } = getRelationForeignKeyFieldPairs(schema, model, relationField);
275
276 return keyPairs.map(({ fk, pk }) => {
277 if (ownedByModel) {
278 // the parent model owns the fk
279 return [`${relationModelAlias}.${pk}`, `${modelAlias}.${fk}`];
280 } else {
281 // the relation side owns the fk
282 return [`${relationModelAlias}.${fk}`, `${modelAlias}.${pk}`];
283 }
284 });
285}
286
287export function makeDefaultOrderBy(schema: SchemaDef, model: string) {
288 const idFields = requireIdFields(schema, model);

Callers 4

buildRelationJoinFilterFunction · 0.90
buildToOneRelationFilterFunction · 0.90
applyRelationOrderByFunction · 0.90
buildCountJsonFunction · 0.90

Calls 1

Tested by

no test coverage detected