Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

anonymous objects problem with pg #18

Open
hwangar opened this issue Dec 29, 2017 · 2 comments
Open

anonymous objects problem with pg #18

hwangar opened this issue Dec 29, 2017 · 2 comments

Comments

@hwangar
Copy link

hwangar commented Dec 29, 2017

Hi there!

Starting with node8, anonymous decorations are showing in pg responses (you can check it at vitaly-t/pg-promise#165), the problem is you're using a strong check using lodash.isPlainObject, which identifies them as NOT plain objects

Could it be a good idea to replace it with lodash.isObject? It looks correct enough to me and won't force postgres users to do a shallow copy before using NestHydrationJS

Greetings!
Juan Arias

@dvalentiate
Copy link
Member

thanks for raising the issue, I'll look into this. I definitely want to support node 8 and haven't yet tested the library in it yet.

@MitMaro
Copy link
Contributor

MitMaro commented Jan 3, 2018

If this is what I think it is, it's not a Node 8 problem.

I hit this problem a while back, and iirc, node-postgres creates an object with a prototype for performance and other reasons. The solution in userland is to remove the prototype from these objects before passing them into the library. Though I agree with the change to lodash.isObject to fix the problem.

const nest = nestHydration().nest;
// data is a response from pg-promise
Reflect.setPrototypeOf(data, null);
return nest(data, definition);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants