Show() to generate joins
iezekiel opened this issue · comments
How can i get from show() the same details as index()
For example.
Tweet.query()
.where(this.params.query)
.join('user')
.end((err, models) => {
this.respond(err || models, ['id', 'body', 'created_at', 'user']);
});
But for show() where i can add join('user') to also select user into model
Tweet.find(this.params.route.id, (err, model) => {
this.respond(err || model);
});
You can either do use the index query with Tweet.query({id: this.params.id}).join('user').end(...)
or you can do (in the find
call):
[...].find((err, model) => {
if (err) {
return this.respond(err);
}
model.include((err, user) => {
// include runs a separate query to grab the user model, returns it as a parameter
// does matching based on parameter name
this.respond(err || model, ['id', 'body', 'created_at', 'user']);
});
});