I'm studying the SailsCasts and I'm working on SailsJS beta version 0.10.
Everything works except when in 0.9.7, I use this:
//subscribe this socket to the User model classroom
// subscribe this socket to the user instance rooms
debug: Deprecated: Model.subscribe(socket, null, ...)
debug: (see http://links.sailsjs.org/docs/config/pubsub)
debug: Please use instance rooms instead (or raw sails.sockets.*() methods.)
I'd prefer to comment (lack rep...), but have you given the docs a good read?
You can't call .subscribe like
User.subscribe(req.socket). It requires a second param
records. So your
User.subscribe(req.socket, users); should work if users is a list of user model instances.
I'm no expert (at all...) with node or sails, but the docs #pubsub claim
model.watch() subscribes clients to publishCreate events for the model instances. I see no mention of publishUpdate,publishDestory, etc. I think it only watches creation events.
.subscribe() takes a list of models (or a model) and subscribes the client to publishAdd, publishDestroy, publishRemove, publishUpdate events (by default) for that list of model instances. You can also specify what contexts you want to subscribe to.
So, it seems you actually want to use
User.watch(req.socket) instead of
.subscribe() if you only want to send the socket publishCreate events. If you need all of them, use something like
If you want to be cool, you can set the
autosubscribe property to contain the list of the contexts you care about and just use
User.subscribe(req.socket,users) the docs - context.