I'm kind of new in node.js and sails but it's easy so I like it :) I'm working actually with the sails Framework 0.10rc3 with MongoDB ans sails-mongo.
I know that the contributors of waterline are not big fan of embedded documents in models as for mongodb (https://github.com/balderdashy/sails-mongo/issues/44#issuecomment-35561040) but anyway, I wanted to know how the 'this' variable works in them and how to retrieve the current element in the inner-array.
Here is an exemple of model (that we can call ProjetSpan):
module.exports = {
attributes: {
proj:
{
model:'Projet'
},
spans:
{
start:
{
type: 'DATETIME',
required: true,
datetime: true,
before: function() {
if (this.end < this.proj.end)
return this.end;
else
return this.proj.end;
}
},
end:
{
type: 'DATETIME',
required: true,
datetime: true,
after: function() {
if (this.start > this.proj.start)
return this.start;
else
return this.proj.start;
}
}
}
}
};
how the 'this' will work in this case ? is 'this' a span (and so this.end will work and not this.proj.end) or is 'this' a ProjetSpan (ans so this.proj.end works but not this.end) ?
Finally, how to make this.end (the variable in the current span) and this.proj.end (the variable in the association of the current document) work in this embedded context ?