docs/src/guide/ref.md
Can be used to create references in a query, such as column- or tablenames. This is a good and shorter alternative to using knex.raw('??', 'tableName.columName') which essentially does the same thing.
knex.ref can be used essentially anywhere in a build-chain. Here is an example:
// @sql
knex(knex.ref('Users').withSchema('TenantId'))
.where(knex.ref('Id'), 1)
.orWhere(knex.ref('Name'), 'Admin')
.select(['Id', knex.ref('Name').as('Username')]);
The Ref function supports schema using .withSchema(string):
knex(knex.ref('users').withSchema('TenantId')).select();
Alias is supported using .alias(string)
// @sql
knex('users').select(knex.ref('Id').as('UserId'));