You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So i have tables events, users and event_participants. For now I'm returning just events by creatorId like this
hook.params.query = {
$or: [
{ creatorId: '' + hook.params.user.id },
{
//TODO Model participants as many to many
}
]
}
But i also need to return associated data from joined table, so i need to return all events that this current user is associated with, so not only where he is creator, but where he is participant through event_participants table.
Also I'm trying to make method that will be called in after: hooks on find and get. In this method i should already have all needed events, but now for each event i need to make array of paricipants where i'm going to include all users that are associated with each event in joined table (event_participants). I was reading docs and i think it has to do something with hydrate/populate/include but couldnt make it work. For now it looks like this unction
includeParticipants(hook) {
return hook.app.service('users').get(hook.params.payload.userId).then(user => {
const model = hook.app.service('users').Model;
const association = { include: [{ model: model, as: 'participants', attributes: ['userId'] }] };
// TODO INCLUDE CRETOR AND PARTICIPANTS
hydrate(association).call(this, hook);
//but it gives me error: 'cannot read property 'Instance' of undefined
hook.result.creator = { fulname: user.ime + ' ' + user.prezime };
return hook;
});
}
Hope its understendable and not too messy. I'm newbie and still trying to figure out how hooks and feathers work.
The text was updated successfully, but these errors were encountered:
In case anyone else comes across a similar issue, looks like hydrate() expects to be called in the context of a service. This worked for me: hydrate(association).call(hook.service, hook);
I have associations like this
So i have tables events, users and event_participants. For now I'm returning just events by creatorId like this
But i also need to return associated data from joined table, so i need to return all events that this current user is associated with, so not only where he is creator, but where he is participant through event_participants table.
Also I'm trying to make method that will be called in after: hooks on find and get. In this method i should already have all needed events, but now for each event i need to make array of paricipants where i'm going to include all users that are associated with each event in joined table (event_participants). I was reading docs and i think it has to do something with hydrate/populate/include but couldnt make it work. For now it looks like this unction
Hope its understendable and not too messy. I'm newbie and still trying to figure out how hooks and feathers work.
The text was updated successfully, but these errors were encountered: