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

publishCreate() generates error after upgrading to v.0.12 #3558

Closed
metalaureate opened this issue Feb 9, 2016 · 6 comments
Closed

publishCreate() generates error after upgrading to v.0.12 #3558

metalaureate opened this issue Feb 9, 2016 · 6 comments
Labels
sockets Relates to sails.sockets.* or resourceful pubsub (RPS) methods, sails.io.js, or sockets in general

Comments

@metalaureate
Copy link

After upgrading https://github.com/maangalabs/socket-in-sails to v.0.12, when I call

Chat.publishCreate({id: data_from_client.id, message : data_from_client.message , user:data_from_client.user},req);

I get error

/Users/shill/Projects/socket-in-sails-master/node_modules/sails/lib/hooks/pubsub/index.js:1069
self.publishCreateSingle(values.toJSON(), req, options);
^
TypeError: undefined is not a function
at /Users/shill/Projects/socket-in-sails-master/node_modules/sails/lib/hooks/pubsub/index.js:1069:43
at arrayEach (/Users/shill/Projects/socket-in-sails-master/node_modules/sails/node_modules/lodash/index.js:1289:13)
at Function. (/Users/shill/Projects/socket-in-sails-master/node_modules/sails/node_modules/lodash/index.js:3345:13)
at publishCreate (/Users/shill/Projects/socket-in-sails-master/node_modules/sails/lib/hooks/pubsub/index.js:1068:11)
at wrapper as publishCreate
at /Users/shill/Projects/socket-in-sails-master/api/controllers/ChatController.js:21:11

This also happens if I port the code to a fresh v.0.12 sails project.

@metalaureate
Copy link
Author

It works if I remove toJSON() from the instruction in /node_modules/sails/lib/hooks/pubsub/index.js:1069

but I do not know what side-effects this causes or why toJSON() is being used vs JSON.stringify

@sgress454
Copy link
Member

Thanks @metalaureate, we'll check it out and post here if we need more info.

@metalaureate
Copy link
Author

I think the problem is that I am not passing bona fide sailsjs model to the publishCreate. It works with this kludge:

payload.toJSON=function () { return payload};

Is there a more elegant way to construct my payload that inherits the toJSON() method from sails?

@sgress454
Copy link
Member

Is there a more elegant way to construct my payload that inherits the toJSON() method from sails?

No, and you shouldn't need to. The publishCreate method should let you send in anything you want, as long as it has a primary key. Looks like I merged in a PR that broke that functionality 😳

I'll look into a fix and some tests to ensure that it doesn't happen again.

@metalaureate
Copy link
Author

You guys are awesome thank you.

@mikermcneil mikermcneil added bug sockets Relates to sails.sockets.* or resourceful pubsub (RPS) methods, sails.io.js, or sockets in general patched-on-master and removed bug labels Feb 9, 2016
@sgress454
Copy link
Member

0.12.1 has been released with this fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sockets Relates to sails.sockets.* or resourceful pubsub (RPS) methods, sails.io.js, or sockets in general
Development

No branches or pull requests

3 participants