(
schema: SchemaDef,
model: string,
modelAlias: string,
relationField: string,
relationModelAlias: string,
)
| 265 | } |
| 266 | |
| 267 | export 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 | |
| 287 | export function makeDefaultOrderBy(schema: SchemaDef, model: string) { |
| 288 | const idFields = requireIdFields(schema, model); |
no test coverage detected