Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions doc/api/query-builder/other-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions typings/objection/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,8 @@ declare namespace Objection {
modelClass: ModelClassMethod<M>;
tableNameFor: TableRefForMethod;
tableRefFor: TableRefForMethod;
tableName(): string;
tableRef(): string;
reject: OneArgMethod<any, this>;
resolve: OneArgMethod<any, this>;
transacting: OneArgMethod<TransactionOrKnex, this>;
Expand Down