feathers icon indicating copy to clipboard operation
feathers copied to clipboard

Explicit table (as `from(...)` / `into(...)`) required (Model)

Open strarsis opened this issue 3 years ago • 1 comments

Steps to reproduce

Retrieve a default FeathersJS service and then the associated Model. Perform KnexJS operations on that Model, e.g. record select(...) or insert(...). The queries fails unless the table name is also explicitly set:

// (e.g. in a service hook)

// Retrieve FeathersJS service and associated Model
const ordersService = app.service('orders');
const ordersModel = ordersService.Model;


// select example
const orders = await ordersModel.select('finished'); // query fails, table undefined in query!

const orders = await ordersModel.select('finished').from('order'); // query works only with table name explicitly stated.


// insert example
const result = await ordersModel.insert(exampleOrders); // query fails, table undefined in query!

const result = await ordersModel.insert(exampleOrders).into('orders'); // query works only with table name explicitly stated.

Expected behavior

No need to explicitly state the table name when the FeathersJS Model service is used.

Actual behavior

Queries all fail unless the table names are explicitly stated.

strarsis avatar Mar 10 '22 14:03 strarsis

@strarsis You will likely get some better traction with this issue by posting it in the feathers-knex repo https://github.com/feathersjs-ecosystem/feathers-knex

DaddyWarbucks avatar Apr 20 '22 19:04 DaddyWarbucks

With the new @feathersjs/knex you can get a reference to to the table by calling service.db([params]):

app.service('orders').db().select('finished')

daffl avatar Oct 15 '22 20:10 daffl