Skip to content

[schema] Composite key #3016

@mdartic

Description

@mdartic

I'm trying to port feathers-objection and discover in the AdapterServiceOptions that id can only be a string

https://github.com/feathersjs/feathers/blob/dove/packages/adapter-commons/src/declarations.ts#L30

How do we manage composite keys ?

For example, in an association table, where the primary key is composed of the two foreign tables.

Actually, I transform the id property of service options in a string | string[] and rewrite some parts of the _find methods like this

    const idColumns = Array.isArray(this.id) ? this.id : [this.id]
    const fullIdColumns = idColumns.map((idc: string) => `${this.table}.${idc}`)

    // provide default sorting if its not set
    if (!filters.$sort) {
      builder.orderBy(
        fullIdColumns.map((fic: string) => ({
          column: fic,
          order: 'asc',
        })) as ColumnRefOrOrderByDescriptor[],
      )
    }

And also for the count request.

Do you think this is the "right" way to do it, or maybe there is another way ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions