Skip to content

Instantly share code, notes, and snippets.

@ndhoule
Created January 31, 2014 00:40
Show Gist options
  • Save ndhoule/8723248 to your computer and use it in GitHub Desktop.
Save ndhoule/8723248 to your computer and use it in GitHub Desktop.
/**
* Appointment
*
* @module :: Model
* @description :: TODO
* @docs :: http://sailsjs.org/#!documentation/models
*/
module.exports = {
attributes: {
name: {
type: 'string'
},
users: {
collection: 'user',
via: 'appointments'
}
}
};
'use strict';
var gravatar = require('../lib/gravatar');
/**
* User
*
* @module :: Model
* @description :: TODO
* @docs :: http://sailsjs.org/#!documentation/models
*/
module.exports = {
attributes: {
appointments: {
collection: 'appointment',
via: 'users'
},
connected: {
type: 'boolean'
},
email: {
type: 'email',
unique: true
},
gravatarHash: {
type: 'string'
},
name: {
type: 'string'
},
username: {
type: 'string'
}
},
beforeUpdate: function(valuesToUpdate, next) {
if (valuesToUpdate.email) {
valuesToUpdate.gravatarHash = gravatar.hash(valuesToUpdate.email);
}
next();
},
beforeCreate: function(values, next) {
if (values.email) {
values.gravatarHash = gravatar.hash(values.email);
}
next();
}
};
// Queries I've tried thus far:
// Client-side, clearly not correct
var query = JSON.stringify({
users: {
contains: 1
}
});
$.get('/assignments?where=' + query, function(res) {
console.log(res);
});
// Server-side, not working either; tried a bunch of permutations of this
Assignment.find()
.where({
users: [1]
})
.exec(/* ... */);
Assignment.find()
.populate('users')
.where({
users: [1]
})
.exec(/* ... */);
@ndhoule
Copy link
Author

ndhoule commented Jan 31, 2014

Error on the first client-side query; I get the appointment.users error any time I query, though:

[err] Server Error (500)
[err] error: column appointment.users does not exist
    at Connection.parseE (/vagrant/node_modules/sails-postgresql/node_modules/pg/lib/connection.js:561:11)
    at Connection.parseMessage (/vagrant/node_modules/sails-postgresql/node_modules/pg/lib/connection.js:390:17)
    at null.<anonymous> (/vagrant/node_modules/sails-postgresql/node_modules/pg/lib/connection.js:92:20)
    at Socket.EventEmitter.emit (events.js:95:17)
    at Socket.<anonymous> (_stream_readable.js:746:14)
    at Socket.EventEmitter.emit (events.js:92:17)
    at emitReadable_ (_stream_readable.js:408:10)
    at emitReadable (_stream_readable.js:404:5)
    at readableAddChunk (_stream_readable.js:165:9)
    at Socket.Readable.push (_stream_readable.js:127:10)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment