Feathers: Can not remove items with cascade option

Created on 25 Sep 2019  路  5Comments  路  Source: feathersjs/feathers

Im using feathers socket.io client.
Can not remove items with foreign keys, even with cascade : true option.
I do that:

      client.service('schedule').remove(this.sid, {
        cascade: true
      }).then(() => ...

This is throws an error:
type: "FeathersError", name: "BadRequest", message: "update or delete on table \"schedule\" violates foreign key constraint \"meetups_sessionId_fkey\" on table \"meetups\""
I try do that:

      client.service('schedule').remove(this.sid, {
        query: {
          cascade: true
        }
      }).then(() => {...

It throws an error:
Object { type: "FeathersError", name: "GeneralError", message: "column schedule.cascade does not exist",
In services multi option is set on true

Most helpful comment

Thanks for answers, problem was been solved.

All 5 comments

You must delete query.cascade after using it so that it does not go into the query to the DB.

You must delete query.cascade after using it so that it does not go into the query to the DB.

This is throws an error like this:
type: "FeathersError", name: "BadRequest", message: "update or delete on table \"schedule\" violates foreign key constraint \"meetups_sessionId_fkey\" on table \"meetups\""

There is no cascade option by default in any of the adapters. It is database specific, if you are e.g. using Sequelize it would have to be in params.sequelize in a before hook.

I thought of something like this:

```js
app.service('schedule').hooks({
before: {
remove: async context => {
const otherService = context.app.service('other');

  await otherService.remove(null, { query: { /**/ } });

  delete context.params.query.cascade;

  return context;
}

}
});

Thanks for answers, problem was been solved.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

perminder-klair picture perminder-klair  路  3Comments

Vincz picture Vincz  路  4Comments

NetOperatorWibby picture NetOperatorWibby  路  4Comments

jordanbtucker picture jordanbtucker  路  4Comments

rstegg picture rstegg  路  3Comments