Created
January 31, 2014 00:40
-
-
Save ndhoule/8723248 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Appointment | |
* | |
* @module :: Model | |
* @description :: TODO | |
* @docs :: http://sailsjs.org/#!documentation/models | |
*/ | |
module.exports = { | |
attributes: { | |
name: { | |
type: 'string' | |
}, | |
users: { | |
collection: 'user', | |
via: 'appointments' | |
} | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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(); | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(/* ... */); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Error on the first client-side query; I get the
appointment.users
error any time I query, though: