Returns the primary key values (or a specific field) of all items in the collection.
(field?: string | string[])
| 578 | |
| 579 | /** Returns the primary key values (or a specific field) of all items in the collection. */ |
| 580 | getIdentifiers<U extends IPrimaryKey = Primary<T> & IPrimaryKey>(field?: string | string[]): U[] { |
| 581 | const items = this.getItems(); |
| 582 | const targetMeta = this.property.targetMeta!; |
| 583 | |
| 584 | if (items.length === 0) { |
| 585 | return []; |
| 586 | } |
| 587 | |
| 588 | field ??= targetMeta.compositePK |
| 589 | ? targetMeta.primaryKeys |
| 590 | : (targetMeta.serializedPrimaryKey ?? targetMeta.primaryKeys[0]); |
| 591 | |
| 592 | const cb = (i: T, f: keyof T) => { |
| 593 | if (Utils.isEntity(i[f], true)) { |
| 594 | return wrap(i[f], true).getPrimaryKey(); |
| 595 | } |
| 596 | |
| 597 | return i[f] as U; |
| 598 | }; |
| 599 | |
| 600 | return items.map(i => { |
| 601 | if (Array.isArray(field)) { |
| 602 | return field.map(f => cb(i, f as keyof T)); |
| 603 | } |
| 604 | |
| 605 | return cb(i, field as keyof T); |
| 606 | }) as U[]; |
| 607 | } |
| 608 | |
| 609 | /** |
| 610 | * @internal |
no test coverage detected