From c8dcf378149d0a8eef4148d7a2e39dce8d2c2b86 Mon Sep 17 00:00:00 2001 From: Ilya Semenov Date: Tue, 22 Jul 2025 18:30:46 +0700 Subject: [PATCH] Add QueryBuilder tableName(), tableRef() Closes #2364 --- doc/api/query-builder/other-methods.md | 18 ++++++++++++++++++ typings/objection/index.d.ts | 2 ++ 2 files changed, 20 insertions(+) diff --git a/doc/api/query-builder/other-methods.md b/doc/api/query-builder/other-methods.md index 98b4cc63a..ef235b65a 100644 --- a/doc/api/query-builder/other-methods.md +++ b/doc/api/query-builder/other-methods.md @@ -131,6 +131,14 @@ Replaces the current context with an empty object. | ----------------------------------- | ---------------------------------- | | [QueryBuilder](/api/query-builder/) | `this` query builder for chaining. | +## tableName() + +```js +const tableName = queryBuilder.tableName(); +``` + +Returns the table name for the query model class. + ## tableNameFor() ```js @@ -151,6 +159,16 @@ Returns the table name for a given model class in the query. Usually the table n | ------ | ------------------------------------------------- | | string | The source table (or view) name for `modelClass`. | +## tableRef() + +```js +const tableRef = queryBuilder.tableRef(); +``` + +Returns the name that should be used to refer to the query's table. +Usually a table can be referred to using its name, but `tableRef` can return a different +value for example in case an alias has been given. + ## tableRefFor() ```js diff --git a/typings/objection/index.d.ts b/typings/objection/index.d.ts index e0cf7d8a2..189d66c61 100644 --- a/typings/objection/index.d.ts +++ b/typings/objection/index.d.ts @@ -1110,6 +1110,8 @@ declare namespace Objection { modelClass: ModelClassMethod; tableNameFor: TableRefForMethod; tableRefFor: TableRefForMethod; + tableName(): string; + tableRef(): string; reject: OneArgMethod; resolve: OneArgMethod; transacting: OneArgMethod;