feathersjs-ecosystem/feathers-vuex

Instance method .save does not work with PostgreSql

lturel opened this issue · 10 comments

Using "feathers-vuex": "@2.0.0-pre.77"
Feathers 4.3.1
At backend PostgreSql pg 7.12.1
Copied the files as described in #216

My store/services/users.js :
:
:
resim

I try to register user info through SignUp.vue component. My script block

resim

My “users” table has the fields:

  • id : uuid
  • email : varchar
  • password: varchar
  • displayName: varchar
  • imageUrl: varchar

In “createUser” method, the marked line
await user.save().then(user => { works perfectly with Mongoose or NeDB.

But with Postgre it gives the error in Browser Console as :

resim

But the following line works with PostgreSql :
await this.create(this.user).then(user => {

How can I make it work with user.save() or is there something wrong elsewhere.

Ah. I see the issue. The __id and __isTemp temporary attributes are getting sent to the server. Those should never be sent to the server. I need to figure out a great way to handle this. The best solution for now is to implement an app-level hook that deletes those two keys from all data objects in create, update, and patch methods.

Here's an example:

const feathersClient = feathers()
  .configure(socketio(socket))
  // .configure(restClient.fetch(window.fetch))
  .configure(authPlugin({ storage: window.localStorage }))
  .hooks({
    before: {
      all: [
        paramsForServer('$populateParams'),
        iff(
          context => ['create', 'update', 'patch'].includes(context.method),
          discard('__id', '__isTemp')
        )
      ]
    }
  })

Hi Marshall, thank you for guiding.
I added the .hook part to feathers-client.js as you described.
In client folder, when "npm run serve", it gives the following errors/warnings:

resim

and when I try to start the client in the browser, console, gives errors:

resim

What should I import in feathers-client.js to get rid of these error? or should I do other customizations? Thanks in advance ...

Oops. Sorry about that. I copied that from one of my project with a custom hook still in place. To fix this:

  1. Remove the paramsForServer line, completely.
  2. Run npm i feathers-hooks-common
  3. Add import { iff } from 'feathers-hooks-common to the top of the feathers-client.js file.

That should get you going, I believe.

I also add "discard" to "import { iff } from 'feathers-hooks-common'" line :)
Works perfectly !

Do you plan to include solution to these issue in next releases?
Thanks a lot for your efforts for community.
All the best,

@lturel good catch. ;)

I do plan to fix them similar to this in the final release.

Hello, are there still plans to add this into the codebase? I implemented the work around hook provided in the comments, but I was just wondering if it is still planned since the issue was closed.

Thanks for the great project!

@fontzter the workaround is now documented as the official solution to this issue. There are cases where saving the temp ids to the db makes sense, so it's what I see as the most Feathers way of accomplishing the task while guaranteeing full flexibility.

@marshallswain Thanks for the quick reply. Sorry, I did not see it in the documentation. It seem that the same is happening when I add fields via the setupInstance method. The added fields end up going to the server on a patch or update. Is that the expected behavior? Should I add a client hook for that as well? Thanks again!

You'll for sure want to add a hook to remove any fields you don't want sent to the server. This will be the official way to control this for a while. I'm working with @J3m5 on a client-side, GraphQL-esqe populate solution that might get an incrementally better experience here. For now, we can just use hooks to keep or discard fields.