Reputation: 4128
I have a Notification
model which belongsToMany
users from users-permissions
plugin.
I have another model called Profile
which belongsToOne
user.
Now, I want to populate
the notification with related user
and their profile
...
I have tried:
await strapi.query("user", "users-permissions").find({_id: `model id`}).populate('profile')
Throwing Impossible to find the plugin where strapi.query has been called.
at me.
Also tried:
notification.user.populate('profile')
No luck either
I also tried strapi.plugins["users-permissions"].models.user
got undefined!
Upvotes: 0
Views: 1688
Reputation: 104
I think this works on the backend side, whilst you are trying to reach it from the front end
Upvotes: 0
Reputation: 31
Global strapi
object do not have either plugins or query properties.
All strapi
object has is as shown in screenshot.
Please note that I am trying to query plugin model from:
/admin/src/containers/HomePage/index.js
Upvotes: 0
Reputation: 559
I am having the same problem here. All of these are undefined:
strapi.query
strapi.plugins
The global strapi
object exists, just doesn't provide the properties listed above...
Am I missing something? I have read the docs at least three times... no luck.
Upvotes: 0
Reputation: 4120
You don't need query
.
You will have to use the mongoose model instance of the User
model of Users & Permissions
plugin.
return strapi.plugins['users-permissions'].models.user.
.findOne(user_id)
.populate('profile');
Upvotes: 0