It all depends on how you want to do queries against your subscriptions later.
SailsJS find method does not handle a way to say User.find({"subscriptions.expires">=today})
directly, if subscriptions is defined as an Array or a Collection.
If you define Subscription as a model, then you can make it a collection in your User model, referencing Subscription, and then you perform queries against Subscription, like Subscrition.find({'expires'>=somedate)
.
The drawback is that this creates a new collection that has the relationship between the two Models, you don't get an embedded object with all your data, if that is what you try to accomplish.
If you want it to be all in an embedded object, you can do it, but then you need to use the Waterline .native method, that allows you to send direct queries in MongoDB NodeJS driver form, as documented in Node.js MongoDB Driver API Documentation
It would be something like
User.native(function(err, collection) {
if (err) {
return console.log(err);
} else {
collection
.find({
'subscriptions.expires': {
$gte: new Date(2012, 7, 14)
}
}, {
'data': 1
}, 0, 1)
.toArray(function(err, subscriptions) {
if (err) {
return console.log(err);
} else {
if (subscriptions.length > 0) {
// Do whatever here
} else {
return console.log('No subscriptions found');
}
}
});
}
});