node.js - Strongloop: how to fetch a related model using code (not REST API) -
having trouble getting related model on user
object. users
have to-many relation customers
.
can not user.customers
grab customers
associated user
?
i have tried
user.find({include:'customers'}, function(err, user) { //now what? //user.customers not work; there no customer array returned. });
happy in docs can't find written.
thank you
in loopback examples create "user" model extension of loopbacks "user" model.
note lower case u.
i had trouble accessing model when using "user" not "user"
user.json
{ "name": "user", "base": "user", "idinjection": true, "emailverificationrequired": false, "properties": { "createdat": { "type": "date" }, "updatedat": { "type": "date" }, .......
user.js
module.exports = function(user) { user.observe('before save', function(ctx, next){ if (ctx.instance) { //if created @ defined if(ctx.instance.createdat){ ctx.instance.updatedat = new date(); } else{ ctx.instance.createdat = ctx.instance.updatedat = new date(); } } else { ctx.data.updatedat = new date(); } next(); })`
Comments
Post a Comment